L2JLisvus

Would you like to react to this message? Create an account in a few clicks or log in to continue.

2 posters

    Tower of Insolence Angels AI [COMMITED]

    Karakan
    Karakan


    Posts : 756
    Join date : 2013-10-04

    Tower of Insolence Angels AI [COMMITED] Empty Tower of Insolence Angels AI [COMMITED]

    Post  Karakan 4th July 2019, 20:01

    Since we all agree that moving from python to java will be overall better
    for the project... I'll start with converting AI files 1by1.

    Any ideas on how to improve the code are welcome.  Cool



    scripts.cfg

    Code:

    Index: scripts.cfg
    ===================================================================
    --- scripts.cfg (revision 620)
    +++ scripts.cfg (working copy)
    @@ -14,7 +14,7 @@
     ai/group_template/feedable_beasts.py
     ai/group_template/FleeingNpc.java
     ai/group_template/FrenzyOnAttack.java
    -ai/group_template/polymorphing_angel.py
     ai/group_template/SearchingMaster.java
    +ai/group_template/TowerOfInsolence.java
     ai/group_template/ValleyOfSaints.java
     





    ...group_template/TowerOfInsolence.java

    Code:


    /*
     * This program is free software: you can redistribute it and/or modify it under
     * the terms of the GNU General Public License as published by the Free Software
     * Foundation, either version 3 of the License, or (at your option) any later
     * version.
     *
     * This program is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     * details.
     *
     * You should have received a copy of the GNU General Public License along with
     * this program. If not, see <http://www.gnu.org/licenses/>.
     */
    package ai.group_template;

    import java.util.HashMap;
    import java.util.Map;

    import net.sf.l2j.gameserver.ai.CtrlIntention;
    import net.sf.l2j.gameserver.model.L2Attackable;
    import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
    import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
    import net.sf.l2j.gameserver.model.quest.Quest;

    /**
     * Tower of Insolence Angels AI
     * By Karakan for L2J-Lisvus
     *
     */
    public class TowerOfInsolence extends Quest
    {
       private static final Map<Integer,Integer[]> ANGELSPAWNS = new HashMap<>();
       static
       {
          ANGELSPAWNS.put(830, new Integer[]{859, 100}); //Guardian Angel
          ANGELSPAWNS.put(831, new Integer[]{860, 100}); //Seal Angel
          ANGELSPAWNS.put(1062, new Integer[]{1063, 100}); //Messenger Angel
          ANGELSPAWNS.put(1067, new Integer[]{1068, 100}); //Guardian Archangel
          ANGELSPAWNS.put(1070, new Integer[]{1071, 100}); //Seal Archangel
       }
      
       public TowerOfInsolence(int questId, String name, String descr)
       {
          super(questId, name, descr);
          int[] mobs = { 830, 1067, 1062, 831, 1070 };
          registerMobs(mobs);
       }
      
       @Override
       public String onKill(L2NpcInstance npc, L2PcInstance killer, boolean isPet)
       {
          int npcId = npc.getNpcId();
          Integer[] spawnData = ANGELSPAWNS.get(npc.getNpcId());
          if (ANGELSPAWNS.containsKey(npcId))
          {
             L2Attackable newNpc = (L2Attackable) addSpawn (spawnData[0], npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0);
             newNpc.onAction(killer);
             newNpc.addDamageHate(killer, 0, 100);
             newNpc.setRunning();
             newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, killer);
          }
          
          return super.onKill(npc, killer, isPet);
       }
      
       public static void main(String[] args)
       {
           // Quest class and state definition
          new TowerOfInsolence(-1, "towerofinsolence", "ai/group_template");
       }
    }


    Last edited by Karakan on 12th July 2019, 15:36; edited 1 time in total
    DnR
    DnR
    Admin
    Admin


    Posts : 1475
    Join date : 2012-12-03
    Age : 34

    Tower of Insolence Angels AI [COMMITED] Empty Re: Tower of Insolence Angels AI [COMMITED]

    Post  DnR 7th July 2019, 00:42

    This is a really good AI, but it's missing pet support which was written in old script.
    I added pet support and a small check to make sure that onAction effect applies to player only if he was targetting previous NPC.
    In the future, I believe that these changes should also apply to the rest of group AI scripts that use onAttack and onKill events.

    Thank you very much for your contribution. Wink

    Best regards,
    DnR
    Karakan
    Karakan


    Posts : 756
    Join date : 2013-10-04

    Tower of Insolence Angels AI [COMMITED] Empty Re: Tower of Insolence Angels AI [COMMITED]

    Post  Karakan 7th July 2019, 12:52

    DnR wrote:This is a really good AI, but it's missing pet support which was written in old script.
    I added pet support and a small check to make sure that onAction effect applies to player only if he was targetting previous NPC.
    In the future, I believe that these changes should also apply to the rest of group AI scripts that use onAttack and onKill events.

    Thank you very much for your contribution. Wink

    Best regards,
    DnR


    Ups.... totally forgot about pets while creating the script Cool

    About onAction:
    I think a check in "onKill" case is not really necessary.

    I can't think of any event where the "killer" can kill a mob without targeting it ?

    Please correct me if im wrong.  study


    Thank you.  Cool
    DnR
    DnR
    Admin
    Admin


    Posts : 1475
    Join date : 2012-12-03
    Age : 34

    Tower of Insolence Angels AI [COMMITED] Empty Re: Tower of Insolence Angels AI [COMMITED]

    Post  DnR 7th July 2019, 13:22

    Karakan wrote:
    About onAction:
    I think a check in "onKill" case is not really necessary.

    I can't think of any event where the "killer" can kill a mob without targeting it ?

    Please correct me if im wrong.  study


    Thank you.  Cool

    That is a good question. Smile
    Think of a player auto-attacking an angel and target some random character in the meantime. Player will still auto-attack angel, but target somebody else (possibly getting ready for pvp/pk).
    Also, this is also related to pets.
    There is the event of player removing target while pet is fighting an angel.
    Also, player can target another NPC (pet itself for example) while pet is fighting an angel.

    Without this check, player will target new angel even though he/she has a different target or no target at all.

    I might be wrong, but I considered this to be the best option for now.
    We can discuss for possible better scenarios, too.

    Best regards,
    DnR
    Karakan
    Karakan


    Posts : 756
    Join date : 2013-10-04

    Tower of Insolence Angels AI [COMMITED] Empty Re: Tower of Insolence Angels AI [COMMITED]

    Post  Karakan 7th July 2019, 13:50

    Ohh...Allright, I see your point now.
    In that case lets keep it that way.

    Thanks for the quick reply. king

    Sponsored content


    Tower of Insolence Angels AI [COMMITED] Empty Re: Tower of Insolence Angels AI [COMMITED]

    Post  Sponsored content


      Current date/time is 19th May 2024, 09:04