| | |
| | | import ChConfig
|
| | | import GameWorld
|
| | | import GameObj
|
| | | import BaseAttack
|
| | | import FBCommon
|
| | | import AICommon
|
| | | import GameMap
|
| | |
|
| | | import random
|
| | |
|
| | |
|
| | | ## 初始化
|
| | |
| | | # @return None
|
| | | # @remarks 函数详细说明.
|
| | | def ProcessAI(curNPC, tick):
|
| | | npcControl = NPCCommon.NPCControl(curNPC)
|
| | | curHP = GameObj.GetHP(curNPC)
|
| | | protectHP = GameObj.GetMaxHP(curNPC) / 2 # 保证血量不低于一半
|
| | | if curHP <= protectHP:
|
| | | GameObj.SetHP(curNPC, curHP + random.randint(protectHP / 3, protectHP))
|
| | | GameWorld.DebugLog("机器人回血!objID=%s" % curNPC.GetID())
|
| | | |
| | | fbPlayer = FBCommon.GetCurSingleFBPlayer()
|
| | | if not fbPlayer:
|
| | | # 副本中没有玩家则不处理
|
| | | GameWorld.DebugLog("副本中没有玩家则不处理!objID=%s" % curNPC.GetID())
|
| | | return
|
| | |
|
| | | curTag = None
|
| | | playerAtkObjID = fbPlayer.GetDictByKey(ChConfig.Def_PlayerKey_LastHurtNPCObjID)
|
| | | if playerAtkObjID:
|
| | | curTag = GameWorld.FindNPCByID(playerAtkObjID)
|
| | | |
| | | npcControl = NPCCommon.NPCControl(curNPC)
|
| | | npcControl.RefreshBuffState(tick)
|
| | | # 没有玩家正在攻击的目标则取自身的仇恨列表
|
| | | if not curTag:
|
| | | #GameWorld.DebugLog("没有玩家正在攻击的目标,刷新自身仇恨目标!objID=%s,maxHP=%s" % (curNPC.GetID(), GameObj.GetMaxHP(curNPC)))
|
| | | npcControl.RefreshAngryList(tick)
|
| | | curNPCAngry = npcControl.GetMaxAngryTag()
|
| | | if curNPCAngry:
|
| | | curNPCAngryType = curNPCAngry.GetObjType()
|
| | | curNPCAngryID = curNPCAngry.GetObjID()
|
| | | curTag = GameWorld.GetObj(curNPCAngryID, curNPCAngryType)
|
| | | |
| | | # 没有攻击目标则跟随玩家
|
| | | if not curTag:
|
| | | #GameWorld.DebugLog("没有攻击目标,跟随玩家!objID=%s" % curNPC.GetID())
|
| | | dist = GameWorld.GetDist(fbPlayer.GetPosX(), fbPlayer.GetPosY(), curNPC.GetPosX(), curNPC.GetPosY())
|
| | | if dist > 12:
|
| | | resultPos = GameMap.GetEmptyPlaceInArea(fbPlayer.GetPosX(), fbPlayer.GetPosY(), 3)
|
| | | curNPC.ResetPos(resultPos.GetPosX(), resultPos.GetPosY())
|
| | | elif dist > 3:
|
| | | npcControl.MoveToObj_Detel(fbPlayer, 3)
|
| | | return
|
| | | __NPCFight(npcControl, curNPC, curTag, tick)
|
| | | return
|
| | |
|
| | | def __NPCFight(npcControl, curNPC, curTag, tick):
|
| | | #设置进入战斗状态
|
| | | NPCCommon.SetNPCInBattleState(curNPC)
|
| | | #开始攻击
|
| | | if curTag == None or GameObj.GetHP(curTag) <= 0:
|
| | | return
|
| | | tagDist = GameWorld.GetDist(curNPC.GetPosX(), curNPC.GetPosY(), curTag.GetPosX(), curTag.GetPosY())
|
| | | GameWorld.DebugLog(" 与目标距离: %s" % tagDist)
|
| | | # if tagDist > 20:
|
| | | # resultPos = GameMap.GetEmptyPlaceInArea(curTag.GetPosX(), curTag.GetPosY(), 3)
|
| | | # curNPC.ResetPos(resultPos.GetPosX(), resultPos.GetPosY())
|
| | | # tagDist = GameWorld.GetDist(curNPC.GetPosX(), curNPC.GetPosY(), curTag.GetPosX(), curTag.GetPosY())
|
| | | |
| | | delayTick = curNPC.GetDictByKey(ChConfig.Def_NPC_Dict_AtkDelayTick)
|
| | | if delayTick:
|
| | | startAtkTick = curNPC.GetDictByKey(ChConfig.Def_NPC_Dict_AtkStartTick)
|
| | | if not startAtkTick:
|
| | | curNPC.SetDict(ChConfig.Def_NPC_Dict_AtkStartTick, tick)
|
| | | startAtkTick = tick
|
| | | if tick - startAtkTick < delayTick:
|
| | | GameWorld.DebugLog("未到攻击时间,暂不处理!objID=%s" % curNPC.GetID())
|
| | | return
|
| | | |
| | | #---优先释放技能---
|
| | | if AICommon.DoAutoUseSkill(curNPC, curTag, tagDist, tick):
|
| | | return
|
| | | #---释放普通攻击---
|
| | | #超过攻击距离,移动过去
|
| | | if tagDist > curNPC.GetAtkDist():
|
| | | npcControl.MoveToObj_Detel(curTag)
|
| | | return
|
| | | if tick - curNPC.GetAttackTick() < curNPC.GetAtkInterval():
|
| | | #攻击间隔没有到, 返回
|
| | | return
|
| | | if npcControl.FixTagPos(curTag.GetPosX(), curTag.GetPosY()):
|
| | | #修正这个NPC的站立位置
|
| | | return
|
| | | #普通攻击
|
| | | BaseAttack.Attack(curNPC, curTag, None, tick)
|
| | | return
|
| | |
|
| | | def OnCheckCanDie(atkObj, curNPC, skill, tick):
|