mangos服务器的游戏对象和ai系统,(搬运工)Mangos服务器的游戏对象和AI系统(二)

CreatureAI这个类并不大,构造函数要传入一个Creature的指针,然后就是20来个接口函数。

构造函数:

explicitCreatureAI(Creature*creature) :m_creature(creature) {}

接口函数不多,可以全部列出来:

// Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter

virtualvoidMoveInLineOfSight(Unit*) {}

// Called for reaction at enter to combat if not in combat yet (enemy can be NULL)

virtualvoidEnterCombat(Unit*/*enemy*/) {}

// Called for reaction at stopping attack at no attackers or targets

virtualvoidEnterEvadeMode() {}

// Called at reaching home after evade

virtualvoidJustReachedHome() {}

// Called at any heal cast/item used (call non implemented)

virtualvoidHealBy(Unit*/*healer*/,uint32/*amount_healed*/) {}

// Called at any Damage to any victim (before damage apply)

virtualvoidDamageDeal(Unit*/*done_to*/,uint32&/*damage*/) {}

// Called at any Damage from any attacker (before damage apply)

// Note: it for recalculation damage or special reaction at damage

// for attack reaction use AttackedBy called for not DOT damage in Unit::DealDamage also

virtualvoidDamageTaken(Unit*/*done_by*/,uint32&/*damage*/) {}

// Called when the creature is killed

virtualvoidJustDied(Unit*) {}

// Called when the creature kills a unit

virtualvoidKilledUnit(Unit*) {}

// Called when the creature summon successfully other creature

virtualvoidJustSummoned(Creature* ) {}

virtualvoidSummonedCreatureDespawn(Creature*/*unit*/) {}

// Called when hit by a spell

virtualvoidSpellHit(Unit*,constSpellEntry*) {}

// Called when spell hits creature's target

virtualvoidSpellHitTarget(Unit*,constSpellEntry*) {}

// Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)

virtualvoidAttackedBy(Unit*attacker);

// Called when creature is spawned or respawned (for reseting variables)

virtualvoidJustRespawned() {}

// Called at waypoint reached or point movement finished

virtualvoidMovementInform(uint32/*MovementType*/,uint32/*Data*/) {}

// Called at text emote receive from player

virtualvoidReceiveEmote(Player*/*pPlayer*/,uint32/*text_emote*/) {}

// Called when creature attack expected (if creature can and no have current victim)

// Note: for reaction at hostile action must be called AttackedBy function.

virtualvoidAttackStart(Unit*) {}

// Is unit visible for MoveInLineOfSight

virtualboolIsVisible(Unit*)const{returnfalse; }

// Called when victim entered water and creature can not enter water

virtualboolcanReachByRangeAttack(Unit*) {returnfalse; }

// Called at World update tick

virtualvoidUpdateAI(constuint32/*diff*/) {}

可以看到,大部分接口是事件触发和消息通知。UpdateAI我放到最后,这个和别的接口函数不同,是负责AI状态的更新处理。

以CreatureAI为基类,派生出了PetAI、CreatureEventAI、GuardAI、ReactorAI、AggressAI、TotemAI和NullCreatureAI 7类基本AI。Creature的AIM_Initialize()函数,对AI进行初始化,根据Creature的类型选择不同的AI。值得提出的是,Mangos还支持ScriptAI,对于非宠物类的生物支持扩展脚本AI。Mangos的脚本系统我还没有怎么看,有空研究下。

可以看到Mangos的AI设计还是比较传统的,Creature类相当于身体和物理存在,干很多“傻大粗”的事情;AI相当于Creature的大脑,对事件进行响应和处理,指挥着身体物理存在进行反应。

下面可以看下宠物AI的一段代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值