bool JSON::GetBoolByName(const char *name, bool defValue) { JSON* item = GetItemByName(name); if (!item || item->Type != JSON_Bool) { return defValue; } else { return (int)item->dValue != 0; } }
String JSON::GetStringByName(const char *name, const String &defValue) { JSON* item = GetItemByName(name); if (!item || item->Type != JSON_String) { return defValue; } else { return item->Value; } }
//----------------------------------------------------------------------------- // Get elements by name double JSON::GetNumberByName(const char *name, double defValue) { JSON* item = GetItemByName(name); if (!item || item->Type != JSON_Number) { return defValue; } else { return item->dValue; } }
int JSON::GetIntByName(const char *name, int defValue) { JSON* item = GetItemByName(name); if (!item || item->Type != JSON_Number) { return defValue; } else { return (int)item->dValue; } }
void ContentPane::AddRequiredResource(_In_ PCWSTR requiredResource) { int iconImage = GENERIC_OBJECT_ICON; std::wstring parseResource = requiredResource; std::vector< std::basic_string<wchar_t> > x; size_t n = std::split(parseResource, x, L'\\', true); if (n > 0) { // Match first item HTREEITEM firstItem = GetItemByName(nullptr, x[0].c_str()); HTREEITEM secondItem = nullptr; HTREEITEM thirdItem = nullptr; if (firstItem == nullptr) { firstItem = _archivePane.InsertItem(x[0].c_str(), FOLDER_OBJECT_ICON, FOLDER_OBJECT_ICON, _gameItem); } secondItem = GetItemByName(firstItem, x[1].c_str()); if (secondItem == nullptr) { iconImage = ResourceObjectTypeToImageIndex(x[1].c_str()); secondItem = _archivePane.InsertItem(x[1].c_str(), iconImage, iconImage, firstItem); _treeItemDataMap[secondItem] = x[0] + L"\\" + x[1]; } if (x.size() > 2) { thirdItem = GetItemByName(secondItem, x[2].c_str()); if (thirdItem == nullptr) { iconImage = ResourceObjectTypeToImageIndex(x[2].c_str()); thirdItem = _archivePane.InsertItem(x[2].c_str(), iconImage, iconImage, secondItem); _treeItemDataMap[thirdItem] = requiredResource; } } _archivePane.Expand(_gameItem, TVE_EXPAND); } }
String ServerMessages::GetMessage(const String &sName) const { std::shared_ptr<ServerMessage> pSM = GetItemByName(sName); if (!pSM) { // Not good, but should never happen. ErrorManager::Instance()->ReportError(ErrorManager::High, 4329, "ServerMessages::GetMessage", "Server message '" + sName + "' could not be found."); return "Server error - Please contact your system administrator."; } return pSM->GetText(); }
HTREEITEM ContentPane::GetItemByName(_In_opt_ HTREEITEM item, _In_ PCWSTR name) { if (item == nullptr) { item = (HTREEITEM)_archivePane.GetRootItem(); } std::wstring itemName = name; while (item != NULL) { wchar_t szBuffer[MAXTEXTLEN+1]; TV_ITEM tvitem; tvitem.hItem = item; tvitem.mask = TVIF_TEXT | TVIF_CHILDREN; tvitem.pszText = szBuffer; tvitem.cchTextMax = MAXTEXTLEN; _archivePane.GetItem(&tvitem); // Did we find it? if (itemName.compare(szBuffer) == 0) return item; // Check whether we have child items. if (tvitem.cChildren) { // Recursively traverse child items. HTREEITEM hItemFound = nullptr; HTREEITEM hItemChild = nullptr; hItemChild = _archivePane.GetChildItem(item); hItemFound = GetItemByName(hItemChild, name); // Did we find it? if (hItemFound != nullptr) return hItemFound; } // Go to next sibling item. item = _archivePane.GetNextSiblingItem(item); } // Not found. return nullptr; }
int JSON::GetArrayByName(const char *name, double values[], int count) { JSON* array = GetItemByName(name); if (!array || array->Type != JSON_Array) return 0; int i = 0; for (JSON* child = array->Children.GetFirst(); !array->Children.IsNull(child); child = array->Children.GetNext(child)) { if (i >= count) break; values[i++] = child->dValue; } OVR_ASSERT(i <= count); return i; }
void MonsterDie(Entity *self,Entity *other) { int i; Monster *monster; int goldcount; if(self == NULL)return; self->state = MS_Dead; self->Acd = 100; if(other != NULL) { if(other->target == self) { /*you killed me, now look away*/ other->target = NULL; } } self->think = NULL; monster = GetMonsterByName(self->name); if(monster == NULL)return; goldcount = monster->gold + (random()*monster->goldchance); if(goldcount > 0)SpawnItemDrop(self->p.x + crandom() * 2, self->p.y + crandom() * 2,"gold", goldcount); /*Item Drops*/ for(i = 0;i < 4;i++) { if(GetItemByName(monster->drops[i]) != NULL) { if(random() < monster->droprate) { SpawnItemDrop(self->p.x + crandom() * 4, self->p.y + crandom() * 4,monster->drops[i], 1); break; } } } /*Earned Grace*/ GivePlayerGrace(monster->grace); /*TODO: Alignment shift*/ /*TODO: Run on-death triggers*/ }
void NPCShopWindow(NPC *npc) { P_Skill *skill; Item *item; int c; int i; int d; int fail = 0; char text[80]; HUDInfo *self; self = Pushwindow(); if(self == NULL) { fprintf(stdout,"Big problem here, can't make NPC Dialog window.\n"); return; } self->stealinput = 1; c = GetShopCount(npc); self->windowupdate = UpdateNPCShopWindow; self->windowdraw = DrawNPCShopWindow; self->box.w = Camera.w * 0.4; self->box.h = (c * FontSize[F_Small]) + (BUTTON_H*2) + 10; self->box.x = Camera.w/2 - self->box.w/2; self->box.y = Camera.h * 0.2; PicButton(self,0,SDLK_RETURN,"Done",self->box.x + self->box.w/2 - (BUTTON_W/2),self->box.y + self->box.h - BUTTON_H - 4,BUTTON_W,BUTTON_H); self->ib = (void *)npc; for(i = 0; i < c; i++) { /*this will need to be corrected for items that are conditional*/ for(d = 0;d < 4;d++) { if(!IsConditionMet(npc->shop[i].condition[d]))fail = 1; } if(!fail) { if(strcmp(npc->shop[i].type,"item")==0) { item = GetItemByName(npc->shop[i].name); if(item == NULL)continue; sprintf(text,"%s - %iG",npc->shop[i].name,(int)(item->cost * npc->shop[i].markup)); } else if(strcmp(npc->shop[i].type,"spell")==0) { skill = GetSpellByName(npc->shop[i].name); if(skill == NULL)continue; sprintf(text,"(Spell) %s - %iG",npc->shop[i].name,(int)(skill->price * npc->shop[i].markup)); } else if(strcmp(npc->shop[i].type,"skill")==0) { skill = GetSkillByName(npc->shop[i].name); if(skill == NULL)continue; sprintf(text,"(Skill) %s - %iG",npc->shop[i].name,(int)(skill->price * npc->shop[i].markup)); } else if(strcmp(npc->shop[i].type,"service")==0) { sprintf(text,"%s",npc->shop[i].name); } TextButton(self,i + 1,SDLK_1 + i,text,self->box.x + self->box.w/2 - (BUTTON_W/2),self->box.y + BUTTON_H + ((FontSize[F_Small] + 1)*i),BUTTON_W,FontSize[F_Small] + 1); } } }
int UpdateNPCShopWindow(HUDInfo *self,int pressID) { char text[80]; int c; int Good; NPC *npc; P_Skill *skill; Item *item; npc = (NPC *)self->ib; c = GetShopCount(npc); switch(pressID) { case 0: PopWindow(self->Handle); return 1; break; } if((pressID >= 1)&&(pressID <= c)) { if(strcmp(npc->shop[pressID - 1].type,"item")==0) { item = GetItemByName(npc->shop[pressID - 1].name); if(item == NULL)return 0; if(PDat.gold >= (item->cost * npc->shop[pressID - 1].markup)) { BuyingPrice = (item->cost * npc->shop[pressID - 1].markup); strcpy(BuyingItem,item->name); sprintf(text,"Buy %s for %iG?",BuyingItem,BuyingPrice); YesNo(text,PurchaseItem,NULL); } else { NewMessage("You can't afford this!",IndexColor(White)); NewMessage("Come back when you have more money!",IndexColor(White)); } } else if(strcmp(npc->shop[pressID - 1].type,"service")==0) { if(strcmp(npc->shop[pressID - 1].name,"Rest")==0) { /*TODO:advance the clock some time...*/ /*TODO address status effects*/ NewMsg("After some rest, you feel better."); PlayerEnt->health = PlayerEnt->healthmax; PlayerEnt->mana = PlayerEnt->manamax; PlayerEnt->stamina = PlayerEnt->staminamax; } else if(strcmp(npc->shop[pressID - 1].name,"Inventory")==0) { /*TODO Open up Stockpile menu*/ NewMsg("To Be Added."); } else if(strcmp(npc->shop[pressID - 1].name,"Upgrade")==0) { /*TODO Open up Stockpile menu*/ NewMsg("To Be Added."); } } else if(strcmp(npc->shop[pressID - 1].type,"spell")==0) { skill = GetSpellByName(npc->shop[pressID - 1].name); if(skill == NULL)return 0; if(PDat.gold >= (skill->price * npc->shop[pressID - 1].markup)) { if(strcmp(skill->type,"favor")==0) { if(GetPlayerItemByName("Wood Relic")!= NULL)/*TODO add other favor castors as needed*/ { BuyingPrice = (skill->price * npc->shop[pressID - 1].markup); strcpy(BuyingItem,skill->name); sprintf(text,"Learn the divine favor %s for %iG?",BuyingItem,BuyingPrice); YesNo(text,PurchaseSpell,NULL); } else { NewMsg("In order to learn this, you will need a Holy Relic"); } } if(strcmp(skill->type,"alchemy")==0) { if(GetPlayerItemByName("White Stone")!= NULL)/*TODO add other favor castors as needed*/ { BuyingPrice = (skill->price * npc->shop[pressID - 1].markup); strcpy(BuyingItem,skill->name); sprintf(text,"Learn how to make %ss for %iG?",BuyingItem,BuyingPrice); YesNo(text,PurchaseSpell,NULL); } else { NewMsg("In order to learn this, you will need a Philosopher's Stone!"); } } } else { NewMsg("I'm afraid I can't afford to teach for free."); } } else if(strcmp(npc->shop[pressID - 1].type,"skill")==0) { skill = GetSkillByName(npc->shop[pressID - 1].name); if(skill == NULL)return 0; Good = 1; if(PDat.gold >= (skill->price * npc->shop[pressID - 1].markup)) { if(SkillHasSpecial(skill,"Strength")) { if(PDat.attr[A_Str].score < 10) { Good = 0; NewMsg("You will need to have more strength than that to learn this skill."); } } if(SkillHasSpecial(skill,"Endurance")) { if(PDat.attr[A_End].score < 10) { Good = 0; NewMsg("I'm sorry, you just are not tough enough to handle this skill."); } } if(SkillHasSpecial(skill,"Agility")) { if(PDat.attr[A_Agi].score < 10) { Good = 0; NewMsg("You will need to work on your footwork before I can teach you this."); } } if(SkillHasSpecial(skill,"Dexterity")) { if(PDat.attr[A_Dex].score < 10) { Good = 0; NewMsg("I'm sorry, but you have stupid hands. If you get new ones come back."); } } if(SkillHasSpecial(skill,"Focus")) { if(PDat.attr[A_Foc].score < 10) { Good = 0; NewMsg("If you can't concentrate, I can't teach you."); } } if(SkillHasSpecial(skill,"Spirit")) { if(PDat.attr[A_Str].score < 10) { Good = 0; NewMsg("You lack the strength of will to understand what I haave to teach you."); } } if(Good) { BuyingPrice = (skill->price * npc->shop[pressID - 1].markup); strcpy(BuyingItem,skill->name); sprintf(text,"Learn the %s skill for %iG?",BuyingItem,BuyingPrice); YesNo(text,PurchaseSkill,NULL); } } else { NewMsg("Training Takes time and MONEY. Come back when you have more of the later."); } } return 1; } return 0; }