本文整理汇总了C++中Being::canFight方法的典型用法代码示例。如果您正苦于以下问题:C++ Being::canFight方法的具体用法?C++ Being::canFight怎么用?C++ Being::canFight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Being
的用法示例。
在下文中一共展示了Being::canFight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: informPlayer
/**
* Informs a player of what happened around the character.
*/
static void informPlayer(MapComposite *map, Character *p)
{
MessageOut moveMsg(GPMSG_BEINGS_MOVE);
MessageOut damageMsg(GPMSG_BEINGS_DAMAGE);
const Point &pold = p->getOldPosition(), ppos = p->getPosition();
int pid = p->getPublicID(), pflags = p->getUpdateFlags();
int visualRange = Configuration::getValue("game_visualRange", 448);
// Inform client about activities of other beings near its character
for (BeingIterator it(map->getAroundBeingIterator(p, visualRange));
it; ++it)
{
Being *o = *it;
const Point &oold = o->getOldPosition(), opos = o->getPosition();
int otype = o->getType();
int oid = o->getPublicID(), oflags = o->getUpdateFlags();
int flags = 0;
// Check if the character p and the moving object o are around.
bool wereInRange = pold.inRangeOf(oold, visualRange) &&
!((pflags | oflags) & UPDATEFLAG_NEW_ON_MAP);
bool willBeInRange = ppos.inRangeOf(opos, visualRange);
if (!wereInRange && !willBeInRange)
{
// Nothing to report: o and p are far away from each other.
continue;
}
if (wereInRange && willBeInRange)
{
// Send attack messages.
if ((oflags & UPDATEFLAG_ATTACK) && oid != pid)
{
MessageOut AttackMsg(GPMSG_BEING_ATTACK);
AttackMsg.writeInt16(oid);
AttackMsg.writeInt8(o->getDirection());
AttackMsg.writeInt8(static_cast< Being * >(o)->getAttackId());
gameHandler->sendTo(p, AttackMsg);
}
// Send action change messages.
if ((oflags & UPDATEFLAG_ACTIONCHANGE))
{
MessageOut ActionMsg(GPMSG_BEING_ACTION_CHANGE);
ActionMsg.writeInt16(oid);
ActionMsg.writeInt8(static_cast< Being * >(o)->getAction());
gameHandler->sendTo(p, ActionMsg);
}
// Send looks change messages.
if (oflags & UPDATEFLAG_LOOKSCHANGE)
{
MessageOut LooksMsg(GPMSG_BEING_LOOKS_CHANGE);
LooksMsg.writeInt16(oid);
Character * c = static_cast<Character * >(o);
serializeLooks(c, LooksMsg);
LooksMsg.writeInt16(c->getHairStyle());
LooksMsg.writeInt16(c->getHairColor());
LooksMsg.writeInt16(c->getGender());
gameHandler->sendTo(p, LooksMsg);
}
// Send emote messages.
if (oflags & UPDATEFLAG_EMOTE)
{
int emoteId = o->getLastEmote();
if (emoteId > -1)
{
MessageOut EmoteMsg(GPMSG_BEING_EMOTE);
EmoteMsg.writeInt16(oid);
EmoteMsg.writeInt16(emoteId);
gameHandler->sendTo(p, EmoteMsg);
}
}
// Send direction change messages.
if (oflags & UPDATEFLAG_DIRCHANGE)
{
MessageOut DirMsg(GPMSG_BEING_DIR_CHANGE);
DirMsg.writeInt16(oid);
DirMsg.writeInt8(o->getDirection());
gameHandler->sendTo(p, DirMsg);
}
// Send damage messages.
if (o->canFight())
{
Being *victim = static_cast< Being * >(o);
const Hits &hits = victim->getHitsTaken();
for (Hits::const_iterator j = hits.begin(),
j_end = hits.end(); j != j_end; ++j)
{
damageMsg.writeInt16(oid);
damageMsg.writeInt16(*j);
//.........这里部分代码省略.........