Ignore:
Timestamp:
Jan 16, 2012 7:56:19 AM (4 months ago)
Author:
MELERIX
Message:

STABLE: Sync with BETA [8629]

Location:
trunk/L2J_DataPack
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/L2J_DataPack

  • trunk/L2J_DataPack/dist/game/data/scripts/ai/group_template/BeastFarm.java

    r7924 r8630  
    3030import com.l2jserver.gameserver.model.actor.instance.L2TamedBeastInstance; 
    3131import com.l2jserver.gameserver.model.quest.QuestState; 
    32 import com.l2jserver.gameserver.network.SystemMessageId; 
    3332import com.l2jserver.gameserver.network.serverpackets.AbstractNpcInfo; 
    3433import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected; 
    35 import com.l2jserver.gameserver.network.serverpackets.SocialAction; 
    3634import com.l2jserver.gameserver.network.serverpackets.StatusUpdate; 
    37 import com.l2jserver.gameserver.network.serverpackets.SystemMessage; 
    3835import com.l2jserver.gameserver.skills.SkillHolder; 
    3936import com.l2jserver.gameserver.templates.chars.L2NpcTemplate; 
     
    4340/** 
    4441 * Growth-capable mobs: Polymorphing upon successful feeding. 
    45  * @author Fulminus 
    46  * Updated to Freya by Gigiikun 
     42 * @author Fulminus Updated to Freya by Gigiikun 
    4743 */ 
    4844public class BeastFarm extends L2AttackableAIScript 
     
    5652        private static final int SKILL_SGRADE_GOLDEN_SPICE = 9053; 
    5753        private static final int SKILL_SGRADE_CRYSTAL_SPICE = 9054; 
    58         private static final int[] TAMED_BEASTS = { 18869, 18870, 18871, 18872 }; 
     54        private static final int[] TAMED_BEASTS = 
     55        { 
     56                18869, 18870, 18871, 18872 
     57        }; 
    5958        private static final int TAME_CHANCE = 20; 
    60         private static final int[] SPECIAL_SPICE_CHANCES = { 33, 75 }; 
     59        private static final int[] SPECIAL_SPICE_CHANCES = 
     60        { 
     61                33, 75 
     62        }; 
    6163         
    6264        // all mobs that can eat... 
    63         private static final int[] FEEDABLE_BEASTS = { 
    64                 18873, 18874, 18875, 18876, 18877, 18878, 18879, 18880, 18881, 18882, 
    65                 18883, 18884, 18885, 18886, 18887, 18888, 18889, 18890, 18891, 18892, 
    66                 18893, 18894, 18895, 18896, 18897, 18898, 18899, 18900 
     65        private static final int[] FEEDABLE_BEASTS = 
     66        { 
     67                18873, 18874, 18875, 18876, 18877, 18878, 18879, 18880, 18881, 18882, 18883, 18884, 18885, 18886, 18887, 18888, 18889, 18890, 18891, 18892, 18893, 18894, 18895, 18896, 18897, 18898, 18899, 18900 
    6768        }; 
    6869         
    69         private static Map<Integer,Integer> _FeedInfo = new FastMap<Integer,Integer>(); 
    70         private static Map<Integer,GrowthCapableMob> _GrowthCapableMobs = new FastMap<Integer,GrowthCapableMob>(); 
     70        private static Map<Integer, Integer> _FeedInfo = new FastMap<Integer, Integer>(); 
     71        private static Map<Integer, GrowthCapableMob> _GrowthCapableMobs = new FastMap<Integer, GrowthCapableMob>(); 
    7172        private static Map<String, SkillHolder[]> _TamedBeastsData = new FastMap<String, SkillHolder[]>(); 
    7273         
     
    7475        private static class GrowthCapableMob 
    7576        { 
    76                 private int _chance; 
    77                 private int _growthLevel; 
    78                 private int _tameNpcId; 
    79                 private Map<Integer,Integer> _skillSuccessNpcIdList = new FastMap<Integer,Integer>(); 
     77                private final int _chance; 
     78                private final int _growthLevel; 
     79                private final int _tameNpcId; 
     80                private final Map<Integer, Integer> _skillSuccessNpcIdList = new FastMap<Integer, Integer>(); 
    8081                 
    8182                public GrowthCapableMob(int chance, int growthLevel, int tameNpcId) 
     
    100101                        if (!_skillSuccessNpcIdList.containsKey(skillId)) 
    101102                                return -1; 
    102                         else if (skillId == SKILL_BLESSED_GOLDEN_SPICE || skillId == SKILL_BLESSED_CRYSTAL_SPICE 
    103                                         || skillId == SKILL_SGRADE_GOLDEN_SPICE || skillId == SKILL_SGRADE_CRYSTAL_SPICE) 
     103                        else if (skillId == SKILL_BLESSED_GOLDEN_SPICE || skillId == SKILL_BLESSED_CRYSTAL_SPICE || skillId == SKILL_SGRADE_GOLDEN_SPICE || skillId == SKILL_SGRADE_CRYSTAL_SPICE) 
    104104                        { 
    105105                                if (Rnd.get(100) < SPECIAL_SPICE_CHANCES[0]) 
     
    112112                                                return _skillSuccessNpcIdList.get(SKILL_CRYSTAL_SPICE); 
    113113                                } 
    114                                 else 
    115                                         return -1; 
     114                                return -1; 
    116115                        } 
    117116                        else if (_growthLevel == 2 && Rnd.get(100) < TAME_CHANCE) 
     
    124123        } 
    125124         
    126         public BeastFarm (int questId, String name, String descr) 
     125        public BeastFarm(int questId, String name, String descr) 
    127126        { 
    128127                super(questId, name, descr); 
    129                 this.registerMobs(FEEDABLE_BEASTS, QuestEventType.ON_KILL, QuestEventType.ON_SKILL_SEE); 
     128                registerMobs(FEEDABLE_BEASTS, QuestEventType.ON_KILL, QuestEventType.ON_SKILL_SEE); 
    130129                 
    131130                GrowthCapableMob temp; 
     
    237236                // Tamed beasts data 
    238237                SkillHolder[] stemp = new SkillHolder[2]; 
    239                 stemp[0] = new SkillHolder(6432,1); 
    240                 stemp[1] = new SkillHolder(6668,1); 
     238                stemp[0] = new SkillHolder(6432, 1); 
     239                stemp[1] = new SkillHolder(6668, 1); 
    241240                _TamedBeastsData.put("%name% of Focus", stemp); 
    242241                 
    243242                stemp = new SkillHolder[2]; 
    244                 stemp[0] = new SkillHolder(6433,1); 
    245                 stemp[1] = new SkillHolder(6670,1); 
     243                stemp[0] = new SkillHolder(6433, 1); 
     244                stemp[1] = new SkillHolder(6670, 1); 
    246245                _TamedBeastsData.put("%name% of Guiding", stemp); 
    247246                 
    248247                stemp = new SkillHolder[2]; 
    249                 stemp[0] = new SkillHolder(6434,1); 
    250                 stemp[1] = new SkillHolder(6667,1); 
     248                stemp[0] = new SkillHolder(6434, 1); 
     249                stemp[1] = new SkillHolder(6667, 1); 
    251250                _TamedBeastsData.put("%name% of Swifth", stemp); 
    252251                 
    253252                stemp = new SkillHolder[1]; 
    254                 stemp[0] = new SkillHolder(6671,1); 
     253                stemp[0] = new SkillHolder(6671, 1); 
    255254                _TamedBeastsData.put("Berserker %name%", stemp); 
    256255                 
    257256                stemp = new SkillHolder[2]; 
    258                 stemp[0] = new SkillHolder(6669,1); 
    259                 stemp[1] = new SkillHolder(6672,1); 
     257                stemp[0] = new SkillHolder(6669, 1); 
     258                stemp[1] = new SkillHolder(6672, 1); 
    260259                _TamedBeastsData.put("%name% of Protect", stemp); 
    261260                 
    262261                stemp = new SkillHolder[2]; 
    263                 stemp[0] = new SkillHolder(6431,1); 
    264                 stemp[1] = new SkillHolder(6666,1); 
     262                stemp[0] = new SkillHolder(6431, 1); 
     263                stemp[1] = new SkillHolder(6666, 1); 
    265264                _TamedBeastsData.put("%name% of Vigor", stemp); 
    266265        } 
     
    275274                } 
    276275                // despawn the old mob 
    277                 //TODO: same code? FIXED? 
    278                 /*if (_GrowthCapableMobs.get(npc.getNpcId()).getGrowthLevel() == 0) 
    279                 { 
    280                         npc.deleteMe(); 
    281                 } 
    282                 else 
    283                 {*/ 
    284                         npc.deleteMe(); 
    285                 //} 
     276                // TODO: same code? FIXED? 
     277                /* 
     278                 * if (_GrowthCapableMobs.get(npc.getNpcId()).getGrowthLevel() == 0) { npc.deleteMe(); } else { 
     279                 */ 
     280                npc.deleteMe(); 
     281                // } 
    286282                 
    287283                // if this is finally a trained mob, then despawn any other trained mobs that the 
    288284                // player might have and initialize the Tamed Beast. 
    289                 if (Util.contains(TAMED_BEASTS,nextNpcId)) 
     285                if (Util.contains(TAMED_BEASTS, nextNpcId)) 
    290286                { 
    291287                        L2NpcTemplate template = NpcTable.getInstance().getTemplate(nextNpcId); 
     
    294290                        String name = _TamedBeastsData.keySet().toArray(new String[_TamedBeastsData.keySet().size()])[Rnd.get(_TamedBeastsData.size())]; 
    295291                        SkillHolder[] skillList = _TamedBeastsData.get(name); 
    296                         switch(nextNpcId) 
     292                        switch (nextNpcId) 
    297293                        { 
    298294                                case 18869: 
     
    311307                        nextNpc.setName(name); 
    312308                        nextNpc.broadcastPacket(new AbstractNpcInfo.NpcInfo(nextNpc, player)); 
    313                         for(SkillHolder sh : skillList) 
     309                        for (SkillHolder sh : skillList) 
    314310                                nextNpc.addBeastSkill(SkillTable.getInstance().getInfo(sh.getSkillId(), sh.getSkillLvl())); 
    315311                        nextNpc.setRunning(); 
    316312                         
    317313                        QuestState st = player.getQuestState("20_BringUpWithLove"); 
    318                         if (st != null && st.getInt("cond") == 1 && st.getQuestItemsCount(7185) == 0 && Rnd.get(10) == 1) 
     314                        if (st != null && st.getInt("cond") == 1 && !st.hasQuestItems(7185) && Rnd.get(10) == 1) 
    319315                        { 
    320                                 //if player has quest 20 going, give quest item 
    321                                 //it's easier to hardcode it in here than to try and repeat this stuff in the quest 
    322                                 st.giveItems(7185,1); 
    323                                 st.set("cond","2"); 
     316                                // if player has quest 20 going, give quest item 
     317                                // it's easier to hardcode it in here than to try and repeat this stuff in the quest 
     318                                st.giveItems(7185, 1); 
     319                                st.set("cond", "2"); 
    324320                        } 
    325321                } 
     
    328324                        // if not trained, the newly spawned mob will automatically be agro against its feeder 
    329325                        // (what happened to "never bite the hand that feeds you" anyway?!) 
    330                         L2Attackable nextNpc = (L2Attackable) this.addSpawn(nextNpcId,npc); 
     326                        L2Attackable nextNpc = (L2Attackable) addSpawn(nextNpcId, npc); 
    331327                         
    332328                        // register the player in the feedinfo for the mob that just spawned 
    333                         _FeedInfo.put(nextNpc.getObjectId(),player.getObjectId()); 
     329                        _FeedInfo.put(nextNpc.getObjectId(), player.getObjectId()); 
    334330                        nextNpc.setRunning(); 
    335                         nextNpc.addDamageHate(player,0,99999); 
     331                        nextNpc.addDamageHate(player, 0, 99999); 
    336332                        nextNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player); 
    337333                         
     
    346342         
    347343        @Override 
    348         public String onSkillSee (L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet) 
     344        public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet) 
    349345        { 
    350346                // this behavior is only run when the target of skill is the passed npc (chest) 
    351347                // i.e. when the player is attempting to open the chest using a skill 
    352                 if (!Util.contains(targets,npc)) 
    353                 { 
    354                         return super.onSkillSee(npc,caster,skill,targets,isPet); 
     348                if (!Util.contains(targets, npc)) 
     349                { 
     350                        return super.onSkillSee(npc, caster, skill, targets, isPet); 
    355351                } 
    356352                // gather some values on local variables 
    357353                int npcId = npc.getNpcId(); 
    358354                int skillId = skill.getId(); 
    359                 // check if the npc and skills used are valid for this script.  Exit if invalid. 
    360                 if (!Util.contains(FEEDABLE_BEASTS,npcId) 
    361                                 || (skillId !=SKILL_GOLDEN_SPICE && skillId != SKILL_CRYSTAL_SPICE 
    362                                                 && skillId !=SKILL_BLESSED_GOLDEN_SPICE && skillId != SKILL_BLESSED_CRYSTAL_SPICE 
    363                                                 && skillId !=SKILL_SGRADE_GOLDEN_SPICE && skillId != SKILL_SGRADE_CRYSTAL_SPICE)) 
    364                 { 
    365                         return super.onSkillSee(npc,caster,skill,targets,isPet); 
     355                // check if the npc and skills used are valid for this script. Exit if invalid. 
     356                if (!Util.contains(FEEDABLE_BEASTS, npcId) || (skillId != SKILL_GOLDEN_SPICE && skillId != SKILL_CRYSTAL_SPICE && skillId != SKILL_BLESSED_GOLDEN_SPICE && skillId != SKILL_BLESSED_CRYSTAL_SPICE && skillId != SKILL_SGRADE_GOLDEN_SPICE && skillId != SKILL_SGRADE_CRYSTAL_SPICE)) 
     357                { 
     358                        return super.onSkillSee(npc, caster, skill, targets, isPet); 
    366359                } 
    367360                 
    368361                // first gather some values on local variables 
    369362                int objectId = npc.getObjectId(); 
    370                 int growthLevel = 3;  // if a mob is in FEEDABLE_BEASTS but not in _GrowthCapableMobs, then it's at max growth (3) 
     363                int growthLevel = 3; // if a mob is in FEEDABLE_BEASTS but not in _GrowthCapableMobs, then it's at max growth (3) 
    371364                if (_GrowthCapableMobs.containsKey(npcId)) 
    372365                { 
     
    378371                if (growthLevel == 0 && _FeedInfo.containsKey(objectId)) 
    379372                { 
    380                         return super.onSkillSee(npc,caster,skill,targets,isPet); 
    381                 } 
    382                 else 
    383                 { 
    384                         _FeedInfo.put(objectId,caster.getObjectId()); 
    385                 } 
     373                        return super.onSkillSee(npc, caster, skill, targets, isPet); 
     374                } 
     375                 
     376                _FeedInfo.put(objectId, caster.getObjectId()); 
    386377                 
    387378                // display the social action of the beast eating the food. 
    388                 npc.broadcastPacket(new SocialAction(npc,2)); 
     379                npc.broadcastSocialAction(2); 
    389380                 
    390381                int food = 0; 
     
    409400                                        _FeedInfo.remove(objectId); 
    410401                                        npc.setRunning(); 
    411                                         ((L2Attackable)npc).addDamageHate(caster,0,1); 
     402                                        ((L2Attackable) npc).addDamageHate(caster, 0, 1); 
    412403                                        npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, caster); 
    413404                                } 
    414                                 return super.onSkillSee(npc,caster,skill,targets,isPet); 
     405                                return super.onSkillSee(npc, caster, skill, targets, isPet); 
    415406                        } 
    416407                        else if (growthLevel > 0 && _FeedInfo.get(objectId) != caster.getObjectId()) 
     
    418409                                // check if this is the same player as the one who raised it from growth 0. 
    419410                                // if no, then do not allow a chance to raise the pet (food gets consumed but has no effect). 
    420                                 return super.onSkillSee(npc,caster,skill,targets,isPet); 
     411                                return super.onSkillSee(npc, caster, skill, targets, isPet); 
    421412                        } 
    422                         spawnNext(npc,caster,newNpcId,food); 
     413                        spawnNext(npc, caster, newNpcId, food); 
    423414                } 
    424415                else 
    425416                { 
    426                         caster.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1).addString("The beast spit out the feed instead of eating it.")); 
    427                         ((L2Attackable)npc).dropItem(caster, food, 1); 
    428                 } 
    429                 return super.onSkillSee(npc,caster,skill,targets,isPet); 
     417                        caster.sendMessage("The beast spit out the feed instead of eating it."); 
     418                        ((L2Attackable) npc).dropItem(caster, food, 1); 
     419                } 
     420                return super.onSkillSee(npc, caster, skill, targets, isPet); 
    430421        } 
    431422         
    432423        @Override 
    433         public String onKill (L2Npc npc, L2PcInstance killer, boolean isPet) 
     424        public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet) 
    434425        { 
    435426                // remove the feedinfo of the mob that got killed, if any 
     
    438429                        _FeedInfo.remove(npc.getObjectId()); 
    439430                } 
    440                 return super.onKill(npc,killer,isPet); 
     431                return super.onKill(npc, killer, isPet); 
    441432        } 
    442433         
     
    444435        { 
    445436                // now call the constructor (starts up the ai) 
    446                 new BeastFarm(-1,"beast_farm","ai"); 
     437                new BeastFarm(-1, "beast_farm", "ai"); 
    447438        } 
    448439} 
Note: See TracChangeset for help on using the changeset viewer.