bool DynamicZoneSlayerMirrorOfAbyss::addMono() { Assert(m_pZone != NULL); // 이성의 봉인을 생성한다. Monster* pMonster = new Monster(792); Assert(pMonster != NULL); pMonster->setName("이성의 봉인"); pMonster->setClanType(33); try { m_pZone->addCreature(pMonster, 15, 15, 2); m_pZone->getMonsterManager()->addEnemy(NULL, pMonster); m_MonoObjectID = pMonster->getObjectID(); } catch (EmptyTileNotExistException& ) { SAFE_DELETE(pMonster); } return true; }
Creature *Session::addCreatureFromScript( char *creatureType, int cx, int cy, int *fx, int *fy, int r ) { Monster *monster = Monster::getMonsterByName( creatureType ); if ( !monster ) { cerr << "*** Error: no monster named " << creatureType << endl; return NULL; } GLShape *shape = getShapePalette()-> getCreatureShape( monster->getModelName(), monster->getSkinName(), monster->getScale(), monster ); Creature *replacement = newCreature( monster, shape ); // register with squirrel registerWithSquirrel( replacement ); bool b = true; if( r > 0 ) { b = replacement->findPlaceBoundedRadial( cx, cy, r ); } else if ( fx && fy ) { b = replacement->findPlace( cx, cy, fx, fy ); } else { //int ffx, ffy; //replacement->findPlace( cx, cy, &ffx, &ffy ); replacement->moveTo( cx, cy, 0 ); getMap()->setCreature( cx, cy, 0, replacement ); } replacement->cancelTarget(); return replacement; }
void Spawn::checkSpawn() { #ifdef __DEBUG_SPAWN__ std::clog << "[Notice] Spawn::checkSpawn " << this << std::endl; #endif Monster* monster; uint32_t spawnId; checkSpawnEvent = 0; for(SpawnedMap::iterator it = spawnedMap.begin(); it != spawnedMap.end();) { spawnId = it->first; monster = it->second; if(monster->isRemoved()) { if(spawnId) spawnMap[spawnId].lastSpawn = OTSYS_TIME(); monster->unRef(); spawnedMap.erase(it++); } else { /*if(spawnId && !isInSpawnZone(monster->getPosition()) && monster->getIdleStatus()) g_game.internalTeleport(monster, monster->getMasterPosition(), true); */++it; } } uint32_t spawnCount = 0; for(SpawnMap::iterator it = spawnMap.begin(); it != spawnMap.end(); ++it) { spawnId = it->first; spawnBlock_t& sb = it->second; if(spawnedMap.count(spawnId)) continue; if(OTSYS_TIME() < sb.lastSpawn + sb.interval) continue; if(findPlayer(sb.pos)) { sb.lastSpawn = OTSYS_TIME(); continue; } spawnMonster(spawnId, sb.mType, sb.pos, sb.direction); ++spawnCount; if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN)) break; } if(spawnedMap.size() < spawnMap.size()) checkSpawnEvent = Scheduler::getInstance().addEvent(createSchedulerTask(getInterval(), boost::bind(&Spawn::checkSpawn, this))); #ifdef __DEBUG_SPAWN__ else std::clog << "[Notice] Spawn::checkSpawn stopped " << this << std::endl; #endif }
void GameLayer::update(float dt) { // check if animationing if (m_isAnimationing) { // init with false m_isAnimationing = false; for (int i = 0; i < m_height * m_width; i++) { Monster *mon = m_matrix[i]; if (mon && mon->getNumberOfRunningActions() > 0) { m_isAnimationing = true; break; } } } // if Monter is moving, ignore use touch event m_isTouchEnable = !m_isAnimationing; if (!m_isAnimationing) { if (m_isNeedFillVacancies) { //爆炸效果结束后才掉落新怪物,增强打击感 fillVacancies(); m_isNeedFillVacancies = false; } else { checkAndRemoveChain(); } } }
void PlayerController::handlePlayerRotateCommand(const ann::util::Dictionary& dict) { std::string direction = dict["direction"].asString(); int angleDiff = 0; Game& game = Game::getInstance(); MonsterDriver* monsterDriver = game.getMonsterDriver(); Monster* player = game.getPlayer(); if (direction == Constants::kRotateDirectionHalfLeft) { monsterDriver->rotateHalfLeft(player); angleDiff = Constants::kMonsterRotateStep; } else if (direction == Constants::kRotateDirectionHalfRight) { monsterDriver->rotateHalfRight(player); angleDiff = -Constants::kMonsterRotateStep; } else { LOGE("Uknown rotation direction %s", direction.c_str()); } ann::util::Dictionary responce; responce["id"] = player->getId(); responce["angleDiff"] = angleDiff; ann::util::NotificationCenter::getInstance().postNotification(Constants::kMonsterRotateNotification, responce); ann::util::NotificationCenter::getInstance().postNotification(Constants::kAllRoundActionsDoneNotification); }
void HelloWorld::addMonster() { // CCSprite* monster = CCSprite::create("monster.png"); Monster* monster = NULL; if (rand() % 2 == 0) { monster = WeakAndFastMonster::create(); } else { monster = StrongAndSlowMonster::create(); } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); int minY = monster->getContentSize().height / 2; int maxY = winSize.height - monster->getContentSize().height / 2; int rangeY = maxY - minY; int actualY = (rand() % rangeY) + minY; monster->setPosition(ccp(winSize.width + monster->getContentSize().width / 2, actualY)); this->addChild(monster); int minDuration = monster->getMinMoveDuration(); int maxDuration = monster->getMaxMoveDuration(); int rangeDuration = maxDuration - minDuration; int actualDuration = (rand() % rangeDuration) + minDuration; CCMoveTo* actionMove = CCMoveTo::create(actualDuration, ccp(-monster->getContentSize().width / 2, actualY)); CCCallFuncN* actionMoveDone = CCCallFuncN::create(this, callfuncN_selector(HelloWorld::spriteMoveFinished)); monster->runAction(CCSequence::create(actionMove, actionMoveDone, NULL)); monster->setTag(1); _monsters->addObject(monster); }
Game::Game(int dungeon_height, int dungeon_width, int number_of_monsters){ // initialize dungeon dungeon = new Dungeon(dungeon_width, dungeon_height); // initialize default weapon Weapon* kurzschwert = new Weapon("Kurzschwert", 2.0); Attributes kurzschwert_mods; kurzschwert_mods.strength = 3; kurzschwert_mods.agility = -1; kurzschwert->setModificators(kurzschwert_mods); // initialize hero gregor_bob = new Hero("Gregor-Bob"); Attributes hero_attribs; hero_attribs.strength = 6; hero_attribs.agility = 7; gregor_bob->setMaxWeight(10.0); gregor_bob->addItem(kurzschwert); gregor_bob->setModificators(hero_attribs); // initialize monsters and distribute over dungeon for(int i = 0; i < number_of_monsters; i++){ Monster* monster = new Monster("generic_monster"); monster_x = rand() % dungeon_width; monster_y = rand() % dungeon_height; Attributes monster_attribs; monster_attribs.strength = 10; monster_attribs.agility = 5; monster->setAttributes(monster_attribs); monster->setCurrentLocation(monster_x, monster_y); dungeon->getRoom(monster_x, monster_y)->addCreature(monster); } }
void Monster::pushCreatures(Tile* tile) { CreatureVector* creatures = tile->getCreatures(); if(!creatures) return; bool effect = false; Monster* monster = NULL; for(uint32_t i = 0; i < creatures->size();) { if((monster = creatures->at(i)->getMonster()) && monster->isPushable()) { if(pushCreature(monster)) continue; monster->setDropLoot(LOOT_DROP_NONE); monster->changeHealth(-monster->getHealth()); if(!effect) effect = true; } ++i; } if(effect) g_game.addMagicEffect(tile->getPosition(), MAGIC_EFFECT_BLOCKHIT); }
TEST (Monster, ReferenceAddressesShouldBeTheSameOnFluenting) { Monster monster ("X", 1); EXPECT_EQ (&monster, &(monster.WithStat (Statistics ()))); EXPECT_EQ (&monster, &(monster.Weaponed (Weapon()))); }
bool Polymorph::Zap(Coord dir) { Monster* monster = get_monster_in_direction(dir, true); if (!monster) return true; //cancel the holding effect as the monster is changing if (game->hero().is_held_by(monster)) { game->hero().clear_hold(); } //restore the level tile, as the new monster may be invisible Coord p = monster->position(); if (game->hero().can_see_monster(monster)) game->screen().add_tile(p, game->level().get_tile(p)); //create a random monster Monster* new_monster = Monster::CreateMonster(rnd(26) + 'A', &p, game->get_level()); new_monster->set_tile_beneath(monster->tile_beneath()); new_monster->m_pack = monster->m_pack; if (new_monster->m_type != monster->m_type) discover(false); if (game->hero().can_see_monster(new_monster)) game->screen().add_tile(p, new_monster->m_type); //the monster chases the player new_monster->start_run(&game->hero()); //destroy the original game->level().monsters.remove(monster); delete monster; return true; }
bool Spawn::spawnMonster(uint32_t spawnId, MonsterType* mType, const Position& pos, Direction dir, bool startup /*= false*/) { Monster* monster = Monster::createMonster(mType); if (!monster) { return false; } if (startup) { //No need to send out events to the surrounding since there is no one out there to listen! if (!g_game.internalPlaceCreature(monster, pos, true)) { delete monster; return false; } } else { if (!g_game.placeCreature(monster, pos, false, true)) { delete monster; return false; } } monster->setDirection(dir); monster->setSpawn(this); monster->setMasterPos(pos, radius); monster->useThing2(); spawnedMap.insert(spawned_pair(spawnId, monster)); spawnMap[spawnId].lastSpawn = OTSYS_TIME(); return true; }
int main() { player.Pos_x = 2; player.Pos_y = 2; player.Frame_Cnt = 0; UnBreakable_Wall().UnBreakable_Wall_Init(); for (int i = 0; i < 10; i++) monster.Monster_Init(); Breakable_Wall().Breakable_Wall_Init(); State(); while (Move_Dir = _getch()) { player.Frame_Cnt++; //20초마다 몬스터 추가 if (player.Frame_Cnt % 20 == 0) monster.Monster_Init(); //사용자 player.Player_Move(&player, Move_Dir); //몬스터 monster.Monster_Move(); monster.Monster_Attack(); //폭탄 bomb.Bomb_Cnt(); //종료 확인 if (End_Flag)return 0; //출력 Output(); } return 0; }
/************************************************************************ * 处理鼠标右击事件 ************************************************************************/ void Controller::HandleRightClick(Point& destPoint) { Player* myPlayer = GetMyPlayer();//GetPlayerManager()->GetPlayer(m_strMyPlayerID); // 把所有的怪物的被选中状态置为未选择状态 Game()->GetMonsterManager()->UnSelectAllMonster(); // 判断鼠标右击区域是否存在一个怪物,如果存在就返回该怪物的指针,否则返回空 Monster* pMonster = Game()->GetMonsterManager()->GetMonster(destPoint); if (pMonster != 0) { m_pCurrentSelectedMonster = pMonster; // 设置该怪物为被选中状态 pMonster->SetSelected(true); // 在怪物血条栏上显示怪物的血量 MonsterLogic::GetInstance()->HandleMonsterBloodChange(pMonster,0); } else { // 清空怪物血条栏上怪物的血量 Game()->GetSceneManager()->SetMonsterBloodProgress(0); } // 获取玩家当前的朝向 int dir = Game()->GetPathManager()->GetDirection(myPlayer->getPosition(),destPoint); // 设置玩家的目的地点(玩家要移动到鼠标右键点击的区域) myPlayer->SetDestPoint(destPoint); // 玩家跑动 myPlayer->Action(CodeMsg::code_player_run,dir); GetNetworkModule()->SendPlayerState(myPlayer); }
void TerrainGenerator::addMissionObjectives( Map *map, ShapePalette *shapePal ) { cerr << "...TerrainGenerator::addMissionObjectives" << endl; if ( mission && !mission->isCompleted() && depth > 0 ) { int startIndex, endIndex; int items = mission->getItemCount(); cerr << "\t...adding items" << endl; if( items > 0 ) { startIndex = depth - 1; endIndex = depth < maxDepth - 1 ? startIndex + 1 : items; cerr << "\t...range=" << startIndex << " to " << endIndex << endl; //cerr << "*** Added mission items: from " << startIndex << " to " << endIndex << endl; // mission objects are on a pedestal // and they are blocking so creatures can't get them for ( int i = startIndex; i < endIndex; i++ ) { RpgItem *rpgItem = mission->getItem( i ); Item *item = scourge->getSession()->newItem( rpgItem, mission->getLevel() ); //mission->addItemInstance( item, rpgItem ); item->setMissionObjectInfo( mission->getMissionId(), i ); item->setBlocking( true ); // don't let monsters pick this up Item *pedestal = scourge->getSession()->newItem( RpgItem::getItemByName( "Pedestal" ) ); int x, y; getRandomLocation( map, pedestal->getShape(), &x, &y ); addItem( map, NULL, pedestal, NULL, x, y ); addItem( map, NULL, item, NULL, x + ( pedestal->getShape()->getWidth() / 2 ) - ( item->getShape()->getWidth() / 2 ), y - ( pedestal->getShape()->getDepth() / 2 ) + ( item->getShape()->getDepth() / 2 ), pedestal->getShape()->getHeight() ); cerr << "\t...Added mission item: " << item->getItemName() << " at: " << x << "," << y << endl; } } cerr << "\t...adding creatures" << endl; int creatures = mission->getCreatureCount(); if( creatures > 0 ) { startIndex = depth - 1; endIndex = depth < maxDepth - 1 ? startIndex + 1 : creatures; cerr << "\t...range=" << startIndex << " to " << endIndex << endl; //cerr << "*** Added mission creatures: from " << startIndex << " to " << endIndex << endl; // add mission creatures for ( int i = startIndex; i < endIndex; i++ ) { int x, y; Monster *monster = mission->getCreature( i ); GLShape *shape = scourge->getSession()->getShapePalette()-> getCreatureShape( monster->getModelName(), monster->getSkinName(), monster->getScale(), monster ); Creature *creature = scourge->getSession()->newCreature( monster, shape ); creature->setMissionObjectInfo( mission->getMissionId(), i ); //mission->addCreatureInstanceMap( creature, monster ); getRandomLocation( map, creature->getShape(), &x, &y ); addItem( map, creature, NULL, NULL, x, y ); creature->moveTo( x, y, 0 ); cerr << "\t...Added mission monster: " << creature->getMonster()->getType() << endl; } } } cerr << "\t...done" << endl; }
void Monster::pushCreatures(Tile* tile) { //We can not use iterators here since we can push a creature to another tile //which will invalidate the iterator. if(CreatureVector* creatures = tile->getCreatures()) { uint32_t removeCount = 0; for(uint32_t i = 0; i < creatures->size();) { Monster* monster = creatures->at(i)->getMonster(); if(monster && monster->isPushable()) { if(pushCreature(monster)) continue; else { monster->changeHealth(-monster->getHealth()); monster->setDropLoot(false); removeCount++; } } ++i; } if(removeCount > 0) g_game.addMagicEffect(tile->getPosition(), NM_ME_BLOCKHIT); } }
void MonsterManager::monsterGenerate(Ogre::SceneManager* sceneManager, float timeSinceLastFrame) { if(mIsStopGenerateMonster) return; /// 怪物波开始 waveBegin(); if(mIsStopGenerateMonster) return; //::CreateThread(NULL, 0, createMonstersThread, sceneManager, NULL, NULL); mMonsterMgr->setTimeCount(mMonsterMgr->getTimeCount() + timeSinceLastFrame); /// std::list<Monster*> monsterList = mMonsterMgr->getMonstersList(); if(mMonsterMgr->getTimeCount() > mNewMonsterTime || mMonsterMgr->getTimeCount() == mNewMonsterTime) { Monster* monster = mCurrentMonsterFactory->createInstance(sceneManager, mMaze, this); /// monster->setScale(0.1, 0.1, 0.1); monster->setAnimate("Walk", true); mMonstersList.push_back(monster); mMonsterMgr->MonsterNumPlus(); mMonsterMgr->setTimeCount(0.0f); mNewMonsterTime = Ogre::Math::RangeRandom(mCurrentWave.timeInteval1, mCurrentWave.timeInteval2); if(mWaveIsBegin) Stage::playSound("../Media/Sound/nextWave.wav", false); mWaveIsBegin = false; } }
void PlayerController::handlePlayerMoveCommand(const ann::util::Dictionary& dict) { std::string directionCommand = dict["direction"].asString(); MoveDirection moveDirection = helpers::parseDirection(directionCommand); Game& game = Game::getInstance(); Monster* player = game.getPlayer(); Position oldPos = player->getPosition(); bool success = game.getMonsterDriver()->tryToMove(player, moveDirection); Position expectedPos = game.getMonsterDriver()->getLastExpectedMovePosition(); ann::util::Dictionary responce; responce["id"] = player->getId(); responce["success"] = success; responce["positionDiff"] = helpers::makeDictionary(expectedPos - oldPos); ann::util::NotificationCenter::getInstance().postNotification(Constants::kMonsterMoveResultNotification, responce); if (success) { ann::util::NotificationCenter::getInstance().postNotification(Constants::kEndOfPlayerTurnNotification); } else { ann::util::NotificationCenter::getInstance().postNotification(Constants::kAllRoundActionsDoneNotification); } }
TEST (Monster, Attack_HitAndDamageRolls) { Monster m = (Monster&) Monster ("m", 50) .Weaponed(Weapon("Sword", Range(1,6))) .WithStat(Statistics() .SetHitPoint(5) .SetAccuracy(12) .SetArmor(5)); Player p1 = (Player&) Player ("P1") .WithStat(Statistics() .SetHitPoint(10) .SetArmor(5) .SetAccuracy(10)); int hitRoll = 0; int damageRoll = 0; m.Attack (p1); //cout << "HIT ROLL " << hitRoll << endl; //cout << "DAMAGE ROLL " << damageRoll << endl; //cout << "PLAYER HP " << p1.GetStatistics().HitPoint () << endl; EXPECT_GE (20, m.GetLastHitRoll()); EXPECT_LE (1, m.GetLastHitRoll()); EXPECT_GE (6, m.GetLastDamageRoll()); EXPECT_LE (0, m.GetLastDamageRoll()); }
Monster* Monster::create(const cocos2d::Color4F &color, Vec2 dir) { Monster *monster = new Monster; monster->init(color, dir); monster->autorelease(); return monster; }
bool EffectObservingEye::canSeeInvisibility(Creature* pTarget ) const throw(Error ) { if (!pTarget->isFlag(Effect::EFFECT_CLASS_INVISIBILITY ) ) return true; Level_t level; if (pTarget->isVampire() ) { Vampire* pVampire = dynamic_cast<Vampire*>(pTarget); Assert(pVampire != NULL); level = pVampire->getLevel(); } else if (pTarget->isMonster() ) { Monster* pMonster = dynamic_cast<Monster*>(pTarget); Assert(pMonster != NULL); level = pMonster->getLevel(); } else { // 뱀파이어나 몬스터가 아니면 못본걸로 한다. return false; } if (m_SkillLevel < level + 40 ) return false; else return true; }
void HelloWorld::update( float dt ) { CCArray* projectilesToDelete = CCArray::create(); CCObject* pObject = NULL; CCObject* pObject2 = NULL; CCARRAY_FOREACH(_projectiles, pObject) { CCSprite* projectile = (CCSprite*)pObject; bool monsterHit = false; CCArray* monstersToDelete = CCArray::create(); CCARRAY_FOREACH(_monsters, pObject2) { Monster* monster = (Monster*)pObject2; if (CCRect::CCRectIntersectsRect(projectile->boundingBox(), monster->boundingBox())) { monsterHit = true; monster->setHp(monster->getHp() - 1); if (monster->getHp() <= 0) { monstersToDelete->addObject(monster); } break; } }
void MonsterAttackingState::update(Monster &monster) { Heroine* target = (Heroine*)monster.getTarget(); if (target == nullptr) return; if (monster.isInDis(target, monster.getAttackDis())) { if (target->getHp () > 0.0f) { monster.attack(target); } else { //TODO monster change to die state target->removeFromParent(); for (int i = 0; i < monster.parent->children.size (); i++) { if (((Monster*)(monster.parent->children[i]))->getTarget() == target) { ((Monster*)(monster.parent->children[i]))->setTarget(nullptr); ((Monster*)(monster.parent->children[i]))->changeState(new MonsterMovingState ()); } } } } else { monster.changeState(new MonsterMovingState ()); } }
bool Player::attack(Monster& monster) { // Combat is turned based: display an options menu. You can, // of course, extend this to let the player use an item, // cast a spell, and so on. int selection = 1; cout << "1) Attack, 2) Run: "; cin >> selection; cout << endl; switch( selection ) { case 1: cout << "You attack an " << monster.getName() << " with a " << mWeapon.mName << endl; if( Random(0, 20) < mAccuracy ) { int damage = Random(mWeapon.mDamageRange); int totalDamage = damage - monster.getArmor(); if( totalDamage <= 0 ) { cout << "Your attack failed to penetrate " << "the armor." << endl; } else { cout << "You attack for " << totalDamage << " damage!" << endl; // Subtract from monster's hitpoints. monster.takeDamage(totalDamage); } } else { cout << "You miss!" << endl; } cout << endl; break; case 2: // 25 % chance of being able to run. int roll = Random(1, 4); if( roll == 1 ) { cout << "You run away!" << endl; return true;//<--Return out of the function. } else { cout << "You could not escape!" << endl; break; } } return false; }
Spawn::~Spawn() { for (const auto& it : spawnedMap) { Monster* monster = it.second; monster->setSpawn(nullptr); monster->decrementReferenceCounter(); } }
/// co_是否返回状态 Bev_Running_Status Co_Back_Status::on_update(NPC *npc) { Monster *monster = npc->monster_self(); if (monster->npc_status() == NPC::BACK_STATUS) { return k_BRS_SUCCESS; } return k_BRS_Failure; }
Spawn::~Spawn() { for (const auto& it : spawnedMap) { Monster* monster = it.second; monster->setSpawn(nullptr); monster->releaseThing2(); } }
/// co_是否有移动目标 Bev_Running_Status Co_Has_Move_Target::on_update(NPC *npc) { Monster *monster = npc->monster_self(); if (monster->walk_path().has_walk_path()) return k_BRS_SUCCESS; return k_BRS_Failure; }
Monster* Monster::create(const std::string& filename, int cntWidth, int cntHeight) { Monster *monster = new Monster(); if (monster && monster->initWithFileName(filename, cntWidth, cntHeight) && monster->init()) { monster->autorelease(); return monster; } CC_SAFE_DELETE(monster); return nullptr; }
/// co_是否空闲状态 Bev_Running_Status Co_Idle_Status::on_update(NPC *npc) { Monster *monster = npc->monster_self(); if (monster->npc_status() != NPC::FIGHT_STATUS && monster->npc_status() != NPC::RECOVER_STATUS) { return k_BRS_SUCCESS; } return k_BRS_Failure; }
Monster* Monster_spawn::generate_monster() { if (!genus || population <= 0) { return NULL; } Monster* ret = new Monster(); ret->set_type( genus->random_member() ); return ret; }