void Handler_PINIT(int* myID, Character *myChar, std::string* str) { SYNCHED_CHARACTER_MAP* chars = SYNCHED_CHARACTER_MAP::getInstance(); SYNCHED_MONSTER_MAP* mons = SYNCHED_MONSTER_MAP::getInstance(); INIT::CONTENTS contents; contents.ParseFromString(*str); Scoped_Wlock SW(&chars->srw); auto user = contents.data(0); int id = user.id(), x = user.x(), y = user.y(); std::string name = user.name(); int lv = user.lv(), maxHp = user.maxhp(), power = user.power(), maxExp = user.maxexp(); int prtExp = user.prtexp(); *myID = id; Character* myCharacter = myChar; myCharacter->setID(id); myCharacter->setName(name); myCharacter->setX(x); myCharacter->setY(y); myCharacter->setLv(lv, maxHp, power, maxExp); myCharacter->setPrtExp(prtExp); chars->insert(id, myChar); printf("- %s님께서 위치 (%d,%d) 에 생성되었습니다!\n", myChar->getName().c_str(), myChar->getX(), myChar->getY()); contents.clear_data(); }
void Handler_PSET_MON(int *myID, std::string* str) { SYNCHED_CHARACTER_MAP* chars = SYNCHED_CHARACTER_MAP::getInstance(); SYNCHED_MONSTER_MAP* mons = SYNCHED_MONSTER_MAP::getInstance(); SET_MONSTER::CONTENTS setmonsterContents; setmonsterContents.ParseFromString(*str); Scoped_Wlock SW(&mons->srw); for (int i = 0; i < setmonsterContents.data_size(); ++i) { auto tmpMon = setmonsterContents.data(i); std::string monName = tmpMon.name(); Monster* mon; if (monName == "기사") { mon = new Knight(tmpMon.id()); } // 일단 else문 달음. 이것 안하면 c4703에러뜸 else { mon = new Knight(); } mon->setX(tmpMon.x()); mon->setY(tmpMon.y()); mon->setLv(tmpMon.lv(), tmpMon.maxhp(), tmpMon.power()); mons->insert(tmpMon.id(), mon); printf("※ 앗!야생의 %s [ID:%d]가 나타났습니다!\n", mon->getName().c_str(), mon->getID()); } setmonsterContents.clear_data(); }
unsigned short UArmor::ar() const { short ar_mod = this->ar_mod(); int ar = ar_base() * hp_ / maxhp(); if ( ar_mod != 0 ) { ar += ar_mod; } if ( ar < 0 ) return 0; else if ( ar <= USHRT_MAX ) return static_cast<unsigned short>( ar ); else return USHRT_MAX; }
void Handler_PUSER_SET_LV(int *myID, std::string* str) { SYNCHED_CHARACTER_MAP* chars = SYNCHED_CHARACTER_MAP::getInstance(); SYNCHED_MONSTER_MAP* mons = SYNCHED_MONSTER_MAP::getInstance(); SET_USER_LV::CONTENTS setuserlvContents; setuserlvContents.ParseFromString(*str); Scoped_Rlock SW(&chars->srw); for (int i = 0; i < setuserlvContents.data_size(); ++i) { auto setuserlv = setuserlvContents.data(i); int id = setuserlv.id(); int lv = setuserlv.lv(); int maxHp = setuserlv.maxhp(); int power = setuserlv.power(); int expUp = setuserlv.expup(); int maxexp = setuserlv.maxexp(); Character* lvUpChar = chars->find(id); if (lvUpChar->getID() == *myID) printf("- 레벨 업을 하였습니다!!\n"); if (lvUpChar == NULL) { printf("나 나오면 안돼는데 나옴?"); exit(0); } else { lvUpChar->setExpUp(expUp); lvUpChar->setLv(lv, maxHp, power, maxexp); printf("★ 유저 %s 님께서 레벨이 %d로 올랐습니다!!\n", lvUpChar->getName().c_str(), id, lv); } } }