本文整理汇总了C++中CreaturePtr类的典型用法代码示例。如果您正苦于以下问题:C++ CreaturePtr类的具体用法?C++ CreaturePtr怎么用?C++ CreaturePtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CreaturePtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseCreatureHealth
void ProtocolGame::parseCreatureHealth(InputMessage& msg)
{
uint id = msg.getU32();
int healthPercent = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setHealthPercent(healthPercent);
}
示例2: parseCreatureSquare
void ProtocolGame::parseCreatureSquare(InputMessage& msg)
{
uint id = msg.getU32();
int color = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->addVolatileSquare(color);
}
示例3: parseCreatureShields
void ProtocolGame::parseCreatureShields(InputMessage& msg)
{
uint id = msg.getU32();
int shield = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setShield(shield);
}
示例4: parseCreatureTurn
void ProtocolGame::parseCreatureTurn(InputMessage& msg)
{
uint id = msg.getU32();
Otc::Direction direction = (Otc::Direction)msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->turn(direction);
}
示例5: parseCreatureSkulls
void ProtocolGame::parseCreatureSkulls(InputMessage& msg)
{
uint id = msg.getU32();
int skull = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setSkull(skull);
}
示例6: parseCreatureSpeed
void ProtocolGame::parseCreatureSpeed(InputMessage& msg)
{
uint id = msg.getU32();
int speed = msg.getU16();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setSpeed(speed);
}
示例7: internalGetOutfit
void ProtocolGame::parseCreatureOutfit(InputMessage& msg)
{
uint id = msg.getU32();
Outfit outfit = internalGetOutfit(msg);
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setOutfit(outfit);
}
示例8: parseCreatureLight
void ProtocolGame::parseCreatureLight(InputMessage& msg)
{
uint id = msg.getU32();
Light light;
light.intensity = msg.getU8();
light.color = msg.getU8();
CreaturePtr creature = g_map.getCreatureById(id);
if(creature)
creature->setLight(light);
}
示例9: isWalkable
bool Tile::isWalkable(bool ignoreCreatures)
{
if(!getGround())
return false;
for(const ThingPtr& thing : m_things) {
if(thing->isNotWalkable())
return false;
if(!ignoreCreatures) {
if(thing->isCreature()) {
CreaturePtr creature = thing->static_self_cast<Creature>();
if(!creature->isPassable() && creature->canBeSeen())
return false;
}
}
}
return true;
}
示例10: follow
void Game::follow(CreaturePtr creature)
{
if(!canPerformGameAction() || creature == m_localPlayer)
return;
// cancel when following again
if(creature && creature == m_followingCreature)
creature = nullptr;
if(creature && isAttacking())
cancelAttack();
setFollowingCreature(creature);
m_localPlayer->stopAutoWalk();
if(m_protocolVersion >= 963) {
if(creature)
m_seq = creature->getId();
} else
m_seq++;
m_protocolGame->sendFollow(creature ? creature->getId() : 0, m_seq);
}
示例11: setFollowingCreature
void LocalPlayer::setFollowingCreature(const CreaturePtr& creature)
{
// clear current following creature
if(m_followingCreature) {
m_followingCreature->hideStaticSquare();
m_followingCreature = nullptr;
}
// set the new attacking creature
if(creature) {
creature->showStaticSquare(Fw::green);
m_followingCreature = creature;
}
}
示例12: addCreature
void Map::addCreature(const CreaturePtr& creature)
{
m_knownCreatures[creature->getId()] = creature;
}
示例13: Point
void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView *lightView)
{
bool animate = drawFlags & Otc::DrawAnimations;
/* Flags to be checked for. */
static const tileflags_t flags[] = {
TILESTATE_HOUSE,
TILESTATE_PROTECTIONZONE,
TILESTATE_OPTIONALZONE,
TILESTATE_HARDCOREZONE,
TILESTATE_NOLOGOUT
};
// first bottom items
if(drawFlags & (Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawOnBottom)) {
m_drawElevation = 0;
for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom())
break;
bool restore = false;
if(g_map.showZones() && thing->isGround()) {
for(unsigned int i = 0; i < sizeof(flags) / sizeof(tileflags_t); ++i) {
tileflags_t flag = flags[i];
if(hasFlag(flag) && g_map.showZone(flag)) {
g_painter->setOpacity(g_map.getZoneOpacity());
g_painter->setColor(g_map.getZoneColor(flag));
restore = true;
break;
}
}
}
if((thing->isGround() && drawFlags & Otc::DrawGround) ||
(thing->isGroundBorder() && drawFlags & Otc::DrawGroundBorders) ||
(thing->isOnBottom() && drawFlags & Otc::DrawOnBottom)) {
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
if(restore) {
g_painter->resetOpacity();
g_painter->resetColor();
}
}
m_drawElevation += thing->getElevation();
if(m_drawElevation > Otc::MAX_ELEVATION)
m_drawElevation = Otc::MAX_ELEVATION;
}
}
int redrawPreviousTopW = 0;
int redrawPreviousTopH = 0;
if(drawFlags & Otc::DrawItems) {
// now common items in reverse order
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
const ThingPtr& thing = *it;
if(thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround() || thing->isCreature())
break;
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
if(thing->isLyingCorpse()) {
redrawPreviousTopW = std::max(thing->getWidth(), redrawPreviousTopW);
redrawPreviousTopH = std::max(thing->getHeight(), redrawPreviousTopH);
}
m_drawElevation += thing->getElevation();
if(m_drawElevation > Otc::MAX_ELEVATION)
m_drawElevation = Otc::MAX_ELEVATION;
}
}
// after we render 2x2 lying corpses, we must redraw previous creatures/ontop above them
if(redrawPreviousTopH > 0 || redrawPreviousTopW > 0) {
int topRedrawFlags = drawFlags & (Otc::DrawCreatures | Otc::DrawEffects | Otc::DrawOnTop | Otc::DrawAnimations);
if(topRedrawFlags) {
for(int x=-redrawPreviousTopW;x<=0;++x) {
for(int y=-redrawPreviousTopH;y<=0;++y) {
if(x == 0 && y == 0)
continue;
const TilePtr& tile = g_map.getTile(m_position.translated(x,y));
if(tile)
tile->draw(dest + Point(x*Otc::TILE_PIXELS, y*Otc::TILE_PIXELS)*scaleFactor, scaleFactor, topRedrawFlags);
}
}
}
}
// creatures
if(drawFlags & Otc::DrawCreatures) {
if(animate) {
for(const CreaturePtr& creature : m_walkingCreatures) {
creature->draw(Point(dest.x + ((creature->getPosition().x - m_position.x)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor,
dest.y + ((creature->getPosition().y - m_position.y)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor), scaleFactor, animate, lightView);
}
}
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
const ThingPtr& thing = *it;
if(!thing->isCreature())
//.........这里部分代码省略.........
示例14: assert
ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
{
ThingPtr thing;
int thingId = msg.getU16();
assert(thingId != 0);
if(thingId == 0x0061 || thingId == 0x0062) { // add new creature
CreaturePtr creature;
if(thingId == 0x0062) { //creature is known
uint id = msg.getU32();
CreaturePtr knownCreature = g_map.getCreatureById(id);
if(knownCreature)
creature = knownCreature;
else
logTraceError("server says creature is known, but its not on creatures list");
} else if(thingId == 0x0061) { //creature is not known
uint removeId = msg.getU32();
uint id = msg.getU32();
std::string name = msg.getString();
if(name.length() > 0) // every creature name must start with a capital letter
name[0] = toupper(name[0]);
g_map.removeCreatureById(removeId);
if(id == m_localPlayer->getId())
creature = m_localPlayer;
else if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId)
creature = PlayerPtr(new Player);
else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId)
creature = MonsterPtr(new Monster);
else if(id >= Proto::NpcStartId && id < Proto::NpcEndId)
creature = NpcPtr(new Npc);
else
logTraceError("creature id is invalid");
creature->setId(id);
creature->setName(name);
}
uint8 healthPercent = msg.getU8();
Otc::Direction direction = (Otc::Direction)msg.getU8();
Outfit outfit = internalGetOutfit(msg);
Light light;
light.intensity = msg.getU8();
light.color = msg.getU8();
int speed = msg.getU16();
int skull = msg.getU8();
int shield = msg.getU8();
int emblem = -1;
if(thingId == 0x0061) // emblem is sent only in packet type 0x61
emblem = msg.getU8();
bool passable = (msg.getU8() == 0);
if(creature) {
creature->setHealthPercent(healthPercent);
creature->setDirection(direction);
creature->setOutfit(outfit);
creature->setLight(light);
creature->setSpeed(speed);
creature->setSkull(skull);
creature->setShield(shield);
if(emblem != -1)
creature->setEmblem(emblem);
creature->setPassable(passable);
creature->setDirection(direction);
if(creature == m_localPlayer) {
m_localPlayer->setKnown(true);
}
}
thing = creature;
} else if(thingId == 0x0063) { // creature turn
parseCreatureTurn(msg);
} else // item
thing = internalGetItem(msg, thingId);
return thing;
}
示例15: if
void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView *lightView)
{
bool animate = drawFlags & Otc::DrawAnimations;
// Added for MapEditor purposes.
// This check will and must evaluate to false if using
// normal client, unless some flag error.
// Save last color
Color lastColor = g_painter->getColor();
if((m_flags & TILESTATE_HOUSE) == TILESTATE_HOUSE)
g_painter->setColor(Color::blue);
else if((m_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE)
g_painter->setColor(Color::green);
// first bottom items
if(drawFlags & (Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawOnBottom)) {
m_drawElevation = 0;
for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom())
break;
if((thing->isGround() && drawFlags & Otc::DrawGround) ||
(thing->isGroundBorder() && drawFlags & Otc::DrawGroundBorders) ||
(thing->isOnBottom() && drawFlags & Otc::DrawOnBottom)) {
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
}
m_drawElevation += thing->getElevation();
if(m_drawElevation > Otc::MAX_ELEVATION)
m_drawElevation = Otc::MAX_ELEVATION;
}
}
int redrawPreviousTopW = 0;
int redrawPreviousTopH = 0;
if(drawFlags & Otc::DrawItems) {
// now common items in reverse order
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
const ThingPtr& thing = *it;
if(thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround() || thing->isCreature())
break;
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
if(thing->isLyingCorpse()) {
redrawPreviousTopW = std::max(thing->getWidth(), redrawPreviousTopW);
redrawPreviousTopH = std::max(thing->getHeight(), redrawPreviousTopH);
}
m_drawElevation += thing->getElevation();
if(m_drawElevation > Otc::MAX_ELEVATION)
m_drawElevation = Otc::MAX_ELEVATION;
}
}
// after we render 2x2 lying corpses, we must redraw previous creatures/ontop above them
if(redrawPreviousTopH > 0 || redrawPreviousTopW > 0) {
int topRedrawFlags = drawFlags & (Otc::DrawCreatures | Otc::DrawEffects | Otc::DrawOnTop | Otc::DrawAnimations);
if(topRedrawFlags) {
for(int x=-redrawPreviousTopW;x<=0;++x) {
for(int y=-redrawPreviousTopH;y<=0;++y) {
if(x == 0 && y == 0)
continue;
const TilePtr& tile = g_map.getTile(m_position.translated(x,y));
if(tile)
tile->draw(dest + Point(x*Otc::TILE_PIXELS, y*Otc::TILE_PIXELS)*scaleFactor, scaleFactor, topRedrawFlags);
}
}
}
}
// creatures
if(drawFlags & Otc::DrawCreatures) {
if(animate) {
for(const CreaturePtr& creature : m_walkingCreatures) {
creature->draw(Point(dest.x + ((creature->getPosition().x - m_position.x)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor,
dest.y + ((creature->getPosition().y - m_position.y)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor), scaleFactor, animate, lightView);
}
}
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
const ThingPtr& thing = *it;
if(!thing->isCreature())
continue;
CreaturePtr creature = thing->static_self_cast<Creature>();
if(creature && (!creature->isWalking() || !animate))
creature->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
}
}
// effects
if(drawFlags & Otc::DrawEffects) {
for(const EffectPtr& effect : m_effects){
effect->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
}
}
// top items
if(drawFlags & Otc::DrawOnTop) {
for(const ThingPtr& thing : m_things) {
//.........这里部分代码省略.........