11package thorny .grasscutters .AttackModifier .commands ;
22
3- import emu .grasscutter .Grasscutter ;
43import emu .grasscutter .command .Command ;
54import emu .grasscutter .command .CommandHandler ;
6- import emu .grasscutter .game .avatar .Avatar ;
75import emu .grasscutter .game .entity .EntityGadget ;
86import emu .grasscutter .game .player .Player ;
9- import emu .grasscutter .game .world .Scene ;
10- import emu .grasscutter .net .proto .VisionTypeOuterClass .VisionType ;
11- import emu .grasscutter .server .game .GameSession ;
12- import emu .grasscutter .server .packet .send .PacketSceneEntityDisappearNotify ;
13- import emu .grasscutter .utils .Position ;
147import emu .grasscutter .command .Command .TargetRequirement ;
15- import emu . grasscutter . data . excels . AvatarSkillDepotData ;
8+ import thorny . grasscutters . AttackModifier . AddAttack ;
169import thorny .grasscutters .AttackModifier .AttackModifier ;
1710import thorny .grasscutters .AttackModifier .utils .*;
18- import thorny .grasscutters .AttackModifier .utils .Config .characters ;
1911
2012import java .util .ArrayList ;
2113import java .util .List ;
2214
2315// Command usage
2416@ Command (label = "attack" , aliases = "at" , usage = "on|off|remove|reload \n set n|e|q [gadgetId]" , targetRequirement = TargetRequirement .PLAYER )
2517public class AttackModifierCommand implements CommandHandler {
26- private static final Config config = AttackModifier .getInstance ().config .getConfig ();
2718 static ArrayList <Integer > blacklistUIDs = AttackModifier .getInstance ().config .getBlacklist ();
28-
29- static List <EntityGadget > activeGadgets = new ArrayList <>(); // Current gadgets
30- static List <EntityGadget > removeGadgets = new ArrayList <>(); // To be removed gadgets
19+ public static final Config gadgetConfig = AttackModifier .getInstance ().config .getGadgetConfig ();
3120
3221 public static boolean toAdd = true ; // Default state to add attacks
3322 public static boolean userCalled = false ; // Whether removeGadget was called by the user
@@ -46,6 +35,7 @@ public void execute(Player sender, Player targetPlayer, List<String> args) {
4635 var pos = targetPlayer .getPosition ();
4736 var rot = targetPlayer .getRotation ();
4837 int thing = 0 ;
38+ int newGadget = -1 ;
4939 String state ;
5040 String avatarName = targetPlayer .getTeamManager ().getCurrentAvatarEntity ().getAvatar ().getAvatarData ().getName ().toLowerCase () + "Ids" ;
5141 int uid = targetPlayer .getUid ();
@@ -75,7 +65,7 @@ public void execute(Player sender, Player targetPlayer, List<String> args) {
7565
7666 if (state .equals ("remove" )) {
7767 userCalled = true ;
78- removeGadgets (scene );
68+ AddAttack . removeGadgets (scene );
7969 CommandHandler .sendMessage (targetPlayer , "Removed all active gadgets!" );
8070 }
8171 if (state .equals ("reload" )) {
@@ -85,139 +75,13 @@ public void execute(Player sender, Player targetPlayer, List<String> args) {
8575 }
8676 if (state .equals ("set" )){
8777 var attackType = args .get (1 ).toLowerCase ();
88- int newGadget = Integer .parseInt (args .get (2 ));
89- characters avatarToChange = null ;
90- try {
91- avatarToChange = getCharacter .getCurrent (avatarName );
92- CommandHandler .sendMessage (targetPlayer , "Setting " + attackType + " to " + newGadget );
93- } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e ) {
94- CommandHandler .sendMessage (targetPlayer , "Failed to set gadget! Change in plugins/AttackModifier/config.json" );
95- }
96- switch (attackType ) {
97- default -> CommandHandler .sendMessage (targetPlayer , "/at set n|e|q [gadgetId]" );
98- case "n" -> avatarToChange .skill .normalAtk = newGadget ; // Normal attack
99- case "e" -> avatarToChange .skill .elementalSkill = newGadget ; // Elemental skill
100- case "q" -> avatarToChange .skill .elementalBurst = newGadget ; // Burst
101- }
102- AttackModifier .getInstance ().reloadConfig ();
78+ try {newGadget = Integer .parseInt (args .get (2 ));}catch (Exception e ){sendUsageMessage (targetPlayer ); return ;}
79+ AddAttack .setGadget (targetPlayer , avatarName , uid , attackType , newGadget );
10380 CommandHandler .sendMessage (targetPlayer , "Set new gadget!" );
10481 }
10582
10683 EntityGadget entity = new EntityGadget (scene , thing , pos , rot );
10784 scene .addEntity (entity );
10885
10986 }
110-
111- public static void addAttack (GameSession session , int skillId , int uid ) {
112-
113- if (!(blacklistUIDs .contains (uid ))) {
114-
115- int addedAttack = 0 ; // Default of no gadget
116- int usedAttack = -1 ; // Default of no attack
117-
118- // Get avatar info
119- Avatar avatar = session .getPlayer ().getTeamManager ().getCurrentAvatarEntity ().getAvatar ();
120- AvatarSkillDepotData skillDepot = avatar .getSkillDepot ();
121-
122- // Check what skill type was used
123- if (skillId == (skillDepot .getSkills ().get (0 ))) {
124- usedAttack = 0 ;
125- }
126- if (skillId == (skillDepot .getSkills ().get (1 ))) {
127- usedAttack = 1 ;
128- }
129- if (skillId == (skillDepot .getEnergySkill ())) {
130- usedAttack = 2 ;
131- }
132-
133- // Get current avatar name
134- String curName = avatar .getAvatarData ().getName ().toLowerCase () + "Ids" ;
135- characters currentAvatar = null ;
136-
137- // Get avatar from config
138- try {
139- currentAvatar = getCharacter .getCurrent (curName );
140- } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e ) {
141- // Should only be called when config is missing entry for the active character
142- Grasscutter .getLogger ().info ("Invalid or missing config for: " + curName );
143- e .printStackTrace ();
144- return ;
145- }
146-
147- // Universal switch
148- switch (usedAttack ) {
149- default -> addedAttack = 0 ;
150- case 0 -> addedAttack = currentAvatar .skill .normalAtk ; // Normal attack
151- case 1 -> addedAttack = currentAvatar .skill .elementalSkill ; // Elemental skill
152- case 2 -> addedAttack = currentAvatar .skill .elementalBurst ; // Burst
153- }
154-
155- // Get position
156- var scene = session .getPlayer ().getScene ();
157- Position pos = new Position (session .getPlayer ().getPosition ());
158- Position rot = new Position (session .getPlayer ().getRotation ());
159- var r = 3 ;
160-
161- // Try to set position in front of player to not get hit
162- double angle = rot .getY ();
163- Position target = new Position (pos );
164-
165- // Only change gadget pos for basic attack
166- if (usedAttack == 0 ) {
167- target .addX ((float ) (r * Math .sin (Math .PI / 180 * angle )));
168- target .addZ ((float ) (r * Math .cos (Math .PI / 180 * angle )));
169- }
170-
171- // Only spawn on match
172- if (addedAttack != 0 ) {
173- EntityGadget att = new EntityGadget (scene , addedAttack , target , rot );
174-
175- // Silly way to track gadget alive time
176- int currTime = (int ) (System .currentTimeMillis () - 1665393100 );
177- att .setGroupId (currTime );
178-
179- activeGadgets .add (att );
180-
181- // Try to make it not hurt self
182- scene .addEntity (att );
183- att .setFightProperty (2001 , 0 );
184- att .setFightProperty (1 , 0 );
185-
186- }
187- // Remove all gadgets when list not empty
188- if (!activeGadgets .isEmpty ()) {
189- removeGadgets (scene );
190- } // if
191- } // if toAdd
192- } // addAttack
193-
194- private static void removeGadgets (Scene scene ) {
195- for (EntityGadget gadget : activeGadgets ) {
196-
197- // When gadgets have lived for 15 sec
198- if (userCalled || (int ) (System .currentTimeMillis () - 1665393100 ) > (gadget .getGroupId () + 15000 )) {
199- // Add to removal list
200- removeGadgets .add (gadget );
201-
202- // Remove entity
203- scene .removeEntity (gadget , VisionType .VISION_TYPE_REMOVE );
204- scene .broadcastPacket (new PacketSceneEntityDisappearNotify (gadget , VisionType .VISION_TYPE_REMOVE ));
205- } // if
206- } // for
207- // Remove gadgets and clean list
208- activeGadgets .removeAll (removeGadgets );
209- removeGadgets .clear ();
210- userCalled = false ;
211- } // removeGadgets
212-
213- public static class getCharacter {
214- public static characters getCurrent (String curName )
215- throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
216- characters curr = new characters ();
217- var me = config .getClass ().getDeclaredField (curName );
218- me .setAccessible (true );
219- curr = (characters ) me .get (config );
220- return curr ;
221- }
222- }
22387} // AttackModifierCommand
0 commit comments