Changeset 5092


Ignore:
Timestamp:
Nov 22, 2011 7:03:54 AM (6 months ago)
Author:
Zoey76
Message:

BETA: More for [5090]:

  • Logger typo fix, thanks UnAfraid? for report.
  • Short skill range typo fix, thanks tukune for report.
  • Format and cleanup.
  • Minor code refactoring to avoid NPEs.
Location:
branches/unstable/L2J_Server_BETA/java/com/l2jserver/gameserver
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/unstable/L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2AttackableAI.java

    r5090 r5092  
    23782378        private FastList<L2Skill> shortRangeSkillRender() 
    23792379        { 
    2380                 shortRangeSkills = _skillrender.getLongRangeSkills(); 
     2380                shortRangeSkills = _skillrender.getShortRangeSkills(); 
    23812381                if (shortRangeSkills.isEmpty()) 
    23822382                { 
  • branches/unstable/L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2ControllableMobAI.java

    r5090 r5092  
    4747public class L2ControllableMobAI extends L2AttackableAI 
    4848{ 
    49         private static final Logger _log = Logger.getLogger(L2AttackableAI.class.getName()); 
     49        private static final Logger _log = Logger.getLogger(L2ControllableMobAI.class.getName()); 
    5050         
    5151        public static final int AI_IDLE = 1; 
     
    7575                        int randY = Rnd.nextInt(MobGroupTable.FOLLOW_RANGE); 
    7676                         
    77                         moveTo(getForcedTarget().getX() + signX * randX, getForcedTarget().getY() + signY * randY, getForcedTarget().getZ()); 
     77                        moveTo(getForcedTarget().getX() + (signX * randX), getForcedTarget().getY() + (signY * randY), getForcedTarget().getZ()); 
    7878                } 
    7979        } 
     
    8383        { 
    8484                if (isThinking()) 
     85                { 
    8586                        return; 
     87                } 
    8688                 
    8789                setThinking(true); 
     
    9395                                case AI_IDLE: 
    9496                                        if (getIntention() != CtrlIntention.AI_INTENTION_ACTIVE) 
     97                                        { 
    9598                                                setIntention(CtrlIntention.AI_INTENTION_ACTIVE); 
     99                                        } 
    96100                                        break; 
    97101                                case AI_FOLLOW: 
     
    109113                                default: 
    110114                                        if (getIntention() == AI_INTENTION_ACTIVE) 
     115                                        { 
    111116                                                thinkActive(); 
     117                                        } 
    112118                                        else if (getIntention() == AI_INTENTION_ATTACK) 
     119                                        { 
    113120                                                thinkAttack(); 
     121                                        } 
    114122                                        break; 
    115123                        } 
     
    125133                L2Attackable npc = (L2Attackable) _actor; 
    126134                 
    127                 if (getAttackTarget() == null || getAttackTarget().isAlikeDead()) 
     135                if ((getAttackTarget() == null) || getAttackTarget().isAlikeDead()) 
    128136                { 
    129137                        setAttackTarget(findNextRndTarget()); 
     
    132140                 
    133141                if (getAttackTarget() == null) 
     142                { 
    134143                        return; 
     144                } 
    135145                 
    136146                npc.setTarget(getAttackTarget()); 
    137147                 
    138148                L2Skill[] skills = null; 
    139                 //double dist2 = 0; 
     149                // double dist2 = 0; 
    140150                 
    141151                try 
    142152                { 
    143153                        skills = _actor.getAllSkills(); 
    144                         //      dist2 = _actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()); 
     154                        // dist2 = _actor.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()); 
    145155                } 
    146156                catch (NullPointerException e) 
     
    156166                        for (L2Skill sk : skills) 
    157167                        { 
    158                                 if (Util.checkIfInRange(sk.getCastRange(), _actor, getAttackTarget(), true) && !_actor.isSkillDisabled(sk) && _actor.getCurrentMp() > _actor.getStat().getMpConsume(sk)) 
     168                                if (Util.checkIfInRange(sk.getCastRange(), _actor, getAttackTarget(), true) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() > _actor.getStat().getMpConsume(sk))) 
    159169                                { 
    160170                                        _accessor.doCast(sk); 
     
    166176                         
    167177                        if (!isNotMoving()) 
     178                        { 
    168179                                moveToPawn(getAttackTarget(), max_range); 
     180                        } 
    169181                         
    170182                        return; 
     
    175187        { 
    176188                L2Character target = getForcedTarget(); 
    177                 if (target == null || target.isAlikeDead()) 
     189                if ((target == null) || target.isAlikeDead()) 
    178190                { 
    179191                        // try to get next group target 
     
    183195                 
    184196                if (target == null) 
     197                { 
    185198                        return; 
     199                } 
    186200                 
    187201                L2Skill[] skills = null; 
     
    208222                } 
    209223                 
    210                 if (!_actor.isMuted() && dist2 > (range + 20) * (range + 20)) 
     224                if (!_actor.isMuted() && (dist2 > ((range + 20) * (range + 20)))) 
    211225                { 
    212226                        // check distant skills 
     
    215229                                int castRange = sk.getCastRange(); 
    216230                                 
    217                                 if (castRange * castRange >= dist2 && !_actor.isSkillDisabled(sk) && _actor.getCurrentMp() > _actor.getStat().getMpConsume(sk)) 
     231                                if (((castRange * castRange) >= dist2) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() > _actor.getStat().getMpConsume(sk))) 
    218232                                { 
    219233                                        _accessor.doCast(sk); 
     
    225239                         
    226240                        if (!isNotMoving()) 
     241                        { 
    227242                                moveToPawn(target, range); 
     243                        } 
    228244                         
    229245                        return; 
     
    234250        protected void thinkForceAttack() 
    235251        { 
    236                 if (getForcedTarget() == null || getForcedTarget().isAlikeDead()) 
     252                if ((getForcedTarget() == null) || getForcedTarget().isAlikeDead()) 
    237253                { 
    238254                        clientStopMoving(null); 
     
    259275                } 
    260276                 
    261                 if (!_actor.isMuted() && dist2 > (range + 20) * (range + 20)) 
     277                if (!_actor.isMuted() && (dist2 > ((range + 20) * (range + 20)))) 
    262278                { 
    263279                        // check distant skills 
     
    266282                                int castRange = sk.getCastRange(); 
    267283                                 
    268                                 if (castRange * castRange >= dist2 && !_actor.isSkillDisabled(sk) && _actor.getCurrentMp() > _actor.getStat().getMpConsume(sk)) 
     284                                if (((castRange * castRange) >= dist2) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() > _actor.getStat().getMpConsume(sk))) 
    269285                                { 
    270286                                        _accessor.doCast(sk); 
     
    276292                         
    277293                        if (!isNotMoving()) 
    278                                 moveToPawn(getForcedTarget(), _actor.getPhysicalAttackRange()/*range*/); 
     294                        { 
     295                                moveToPawn(getForcedTarget(), _actor.getPhysicalAttackRange()/* range */); 
     296                        } 
    279297                         
    280298                        return; 
     
    286304        protected void thinkAttack() 
    287305        { 
    288                 if (getAttackTarget() == null || getAttackTarget().isAlikeDead()) 
     306                if ((getAttackTarget() == null) || getAttackTarget().isAlikeDead()) 
    289307                { 
    290308                        if (getAttackTarget() != null) 
     
    305323                                 
    306324                                Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values(); 
    307  
     325                                 
    308326                                for (L2Object obj : objs) 
    309327                                { 
    310328                                        if (!(obj instanceof L2Npc)) 
     329                                        { 
    311330                                                continue; 
     331                                        } 
    312332                                         
    313333                                        L2Npc npc = (L2Npc) obj; 
    314334                                         
    315335                                        if (!faction_id.equals(npc.getFactionId())) 
     336                                        { 
    316337                                                continue; 
     338                                        } 
    317339                                         
    318                                         if (_actor.isInsideRadius(npc, npc.getFactionRange(), false, true) && Math.abs(getAttackTarget().getZ() - npc.getZ()) < 200) 
     340                                        if (_actor.isInsideRadius(npc, npc.getFactionRange(), false, true) && (Math.abs(getAttackTarget().getZ() - npc.getZ()) < 200)) 
    319341                                        { 
    320342                                                npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1); 
     
    341363                        } 
    342364                         
    343                         if (!_actor.isMuted() && dist2 > (range + 20) * (range + 20)) 
     365                        if (!_actor.isMuted() && (dist2 > ((range + 20) * (range + 20)))) 
    344366                        { 
    345367                                // check distant skills 
     
    348370                                        int castRange = sk.getCastRange(); 
    349371                                         
    350                                         if (castRange * castRange >= dist2 && !_actor.isSkillDisabled(sk) && _actor.getCurrentMp() > _actor.getStat().getMpConsume(sk)) 
     372                                        if (((castRange * castRange) >= dist2) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() > _actor.getStat().getMpConsume(sk))) 
    351373                                        { 
    352374                                                _accessor.doCast(sk); 
     
    365387                         
    366388                        if (_actor.isConfused()) 
     389                        { 
    367390                                hated = findNextRndTarget(); 
     391                        } 
    368392                        else 
     393                        { 
    369394                                hated = getAttackTarget(); 
     395                        } 
    370396                         
    371397                        if (hated == null) 
     
    376402                         
    377403                        if (hated != getAttackTarget()) 
     404                        { 
    378405                                setAttackTarget(hated); 
    379                          
    380                         if (!_actor.isMuted() && skills.length > 0 && Rnd.nextInt(5) == 3) 
     406                        } 
     407                         
     408                        if (!_actor.isMuted() && (skills.length > 0) && (Rnd.nextInt(5) == 3)) 
    381409                        { 
    382410                                for (L2Skill sk : skills) 
     
    384412                                        int castRange = sk.getCastRange(); 
    385413                                         
    386                                         if (castRange * castRange >= dist2 && !_actor.isSkillDisabled(sk) && _actor.getCurrentMp() < _actor.getStat().getMpConsume(sk)) 
     414                                        if (((castRange * castRange) >= dist2) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() < _actor.getStat().getMpConsume(sk))) 
    387415                                        { 
    388416                                                _accessor.doCast(sk); 
     
    402430                 
    403431                if (_actor.isConfused()) 
     432                { 
    404433                        hated = findNextRndTarget(); 
     434                } 
    405435                else 
     436                { 
    406437                        hated = getAttackTarget(); 
     438                } 
    407439                 
    408440                if (hated != null) 
     
    415447        private boolean autoAttackCondition(L2Character target) 
    416448        { 
    417                 if (target == null || !(_actor instanceof L2Attackable)) 
     449                if ((target == null) || !(_actor instanceof L2Attackable)) 
     450                { 
    418451                        return false; 
     452                } 
    419453                L2Attackable me = (L2Attackable) _actor; 
    420454                 
    421                 if (target instanceof L2NpcInstance || target instanceof L2DoorInstance) 
     455                if ((target instanceof L2NpcInstance) || (target instanceof L2DoorInstance)) 
     456                { 
    422457                        return false; 
    423                  
    424                 if (target.isAlikeDead() || !me.isInsideRadius(target, me.getAggroRange(), false, false) || Math.abs(_actor.getZ() - target.getZ()) > 100) 
     458                } 
     459                 
     460                if (target.isAlikeDead() || !me.isInsideRadius(target, me.getAggroRange(), false, false) || (Math.abs(_actor.getZ() - target.getZ()) > 100)) 
     461                { 
    425462                        return false; 
     463                } 
    426464                 
    427465                // Check if the target isn't invulnerable 
    428466                if (target.isInvul()) 
     467                { 
    429468                        return false; 
     469                } 
    430470                 
    431471                // Spawn protection (only against mobs) 
    432                 if(target instanceof L2PcInstance && ((L2PcInstance)target).isSpawnProtected()) 
     472                if ((target instanceof L2PcInstance) && ((L2PcInstance) target).isSpawnProtected()) 
     473                { 
    433474                        return false; 
     475                } 
    434476                 
    435477                // Check if the target is a L2PlayableInstance 
     
    438480                        // Check if the target isn't in silent move mode 
    439481                        if (((L2Playable) target).isSilentMoving()) 
     482                        { 
    440483                                return false; 
     484                        } 
    441485                } 
    442486                 
    443487                if (target instanceof L2Npc) 
     488                { 
    444489                        return false; 
     490                } 
    445491                 
    446492                return me.isAggressive(); 
     
    461507                { 
    462508                        if (!(obj instanceof L2Character)) 
     509                        { 
    463510                                continue; 
     511                        } 
    464512                         
    465513                        npcX = npc.getX(); 
     
    471519                        dy = npcY - targetY; 
    472520                         
    473                         if (dx * dx + dy * dy > dblAggroRange) 
     521                        if (((dx * dx) + (dy * dy)) > dblAggroRange) 
     522                        { 
    474523                                continue; 
     524                        } 
    475525                         
    476526                        L2Character target = (L2Character) obj; 
    477527                         
    478                         if (autoAttackCondition(target)) // check aggression 
     528                        if (autoAttackCondition(target)) 
     529                        { 
    479530                                potentialTarget.add(target); 
    480                 } 
    481                  
    482                  
    483                 if (potentialTarget.isEmpty()) // nothing to do 
     531                        } 
     532                } 
     533                 
     534                if (potentialTarget.isEmpty()) 
     535                { 
    484536                        return null; 
     537                } 
    485538                 
    486539                // we choose a random target 
  • branches/unstable/L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/L2Npc.java

    r5083 r5092  
    297297        public FastList<L2Skill> getLongRangeSkill() 
    298298        { 
    299                 FastList<L2Skill> skilldata = new FastList<L2Skill>(); 
    300                 boolean hasLrange = false; 
     299                final FastList<L2Skill> skilldata = new FastList<>(); 
    301300                if (_staticAIData == null || _staticAIData.getLongRangeSkill() == 0) 
     301                { 
    302302                        return null; 
    303                  
     303                } 
    304304                switch (_staticAIData.getLongRangeSkill()) 
    305305                { 
     
    318318                                                { 
    319319                                                        skilldata.add(sk); 
    320                                                         hasLrange = true; 
    321320                                                } 
    322321                                        } 
     
    333332                                                { 
    334333                                                        skilldata.add(sk); 
    335                                                         hasLrange = true; 
    336334                                                } 
    337335                                        } 
     
    346344                                        { 
    347345                                                skilldata.add(sk); 
    348                                                 hasLrange = true; 
    349346                                        } 
    350347                                } 
    351348                        } 
    352349                } 
    353                  
    354                 return (hasLrange ? skilldata : null); 
     350                return skilldata; 
    355351        } 
    356352         
    357353        public FastList<L2Skill> getShortRangeSkill() 
    358354        { 
    359                 FastList<L2Skill> skilldata = new FastList<L2Skill>(); 
    360                 boolean hasSrange = false; 
     355                final FastList<L2Skill> skilldata = new FastList<>(); 
    361356                if (_staticAIData == null || _staticAIData.getShortRangeSkill() == 0) 
    362                         return null; 
    363                  
     357                { 
     358                        return skilldata; 
     359                } 
    364360                switch (_staticAIData.getShortRangeSkill()) 
    365361                { 
     
    373369                                        { 
    374370                                                if (sk == null || sk.isPassive() || sk.getTargetType() == L2TargetType.TARGET_SELF) 
     371                                                { 
    375372                                                        continue; 
    376                                                  
     373                                                } 
    377374                                                if (sk.getCastRange() <= 200) 
    378375                                                { 
    379376                                                        skilldata.add(sk); 
    380                                                         hasSrange = true; 
    381377                                                } 
    382378                                        } 
     
    393389                                                { 
    394390                                                        skilldata.add(sk); 
    395                                                         hasSrange = true; 
    396391                                                } 
    397392                                        } 
     
    406401                                        { 
    407402                                                skilldata.add(sk); 
    408                                                 hasSrange = true; 
    409403                                        } 
    410404                                } 
    411405                        } 
    412406                } 
    413                  
    414                 return (hasSrange ? skilldata : null); 
     407                return skilldata; 
    415408        } 
    416409         
Note: See TracChangeset for help on using the changeset viewer.