111 lines
5.5 KiB
C++
111 lines
5.5 KiB
C++
// PORT: AVA2 bio.* system. The extracted core preserves its 13 stages and reward accumulation.
|
|
#include "questpc.h"
|
|
#include "item_manager.h"
|
|
#include "item.h"
|
|
#include <sstream>
|
|
#include <vector>
|
|
static void BioSplitArgument(const char* argument, std::vector<std::string>& out) {
|
|
// AVA2 split_argument includes the sub-command at index 1.
|
|
out.push_back("bio"); std::istringstream input(argument); std::string word;
|
|
while (input >> word) out.push_back(word);
|
|
}
|
|
static unsigned BioPointIdentity(unsigned point) { return point; }
|
|
#include "ava2_biolog_core.h"
|
|
|
|
static void SendBioState(LPCHARACTER ch) {
|
|
int stage=ch->GetQuestFlag("bio.level");
|
|
if (stage==0) {stage=1;ch->SetQuestFlag("bio.level",1);}
|
|
if (stage<1 || stage>=int(bio_max)) ch->ChatPacket(CHAT_TYPE_COMMAND,"bioempty");
|
|
else {
|
|
int count=ch->GetQuestFlag("bio.count");
|
|
ch->ChatPacket(CHAT_TYPE_COMMAND,"biotime %d",int(get_global_time()));
|
|
ch->ChatPacket(CHAT_TYPE_COMMAND,"biodata %d %d %d",stage,count,ch->GetQuestFlag("bio.time"));
|
|
if (count>=int(bio_data[stage][2])) {
|
|
if (count==int(bio_data[stage][2]) && bio_data[stage][5]) ch->ChatPacket(CHAT_TYPE_COMMAND,"biostone %d",stage);
|
|
else if (bio_data[stage][14]) ch->ChatPacket(CHAT_TYPE_COMMAND,"bioodul %d",stage);
|
|
}
|
|
}
|
|
// Completed characters still need their selections for the 70028 reselection UI.
|
|
std::ostringstream bonuses;
|
|
for (unsigned i=1;i<bio_max;++i) {
|
|
char flag[40];snprintf(flag,sizeof(flag),"bio.bonus%u",i);
|
|
bonuses << ' ' << ch->GetQuestFlag(flag);
|
|
}
|
|
ch->ChatPacket(CHAT_TYPE_COMMAND,"biobonuses%s",bonuses.str().c_str());
|
|
}
|
|
|
|
#include "ava2_biolog_shop.h"
|
|
|
|
static bool BioShopBuy(LPCHARACTER ch, unsigned index) {
|
|
if (index>=sizeof(kBioShop)/sizeof(kBioShop[0])) return false;
|
|
const BioShopEntry& offer=kBioShop[index];
|
|
if ((offer.cost && ch->CountSpecifyItem(offer.cost)<int(offer.amount)) ||
|
|
(!offer.cost && ch->GetGold()<int(offer.gold))) {
|
|
ch->ChatPacket(CHAT_TYPE_COMMAND,"BioNotice cost"); return true;
|
|
}
|
|
LPITEM item=ch->AutoGiveItem(offer.vnum,offer.count,-1,true);
|
|
if (!item) return true;
|
|
if (offer.cost) ch->RemoveSpecifyItem(offer.cost,offer.amount);
|
|
else ch->PointChange(POINT_GOLD,-int(offer.gold),false);
|
|
ITEM_MANAGER::instance().FlushDelayedSave(item);
|
|
ch->ChatPacket(CHAT_TYPE_COMMAND,"BioNotice bought");
|
|
return true;
|
|
}
|
|
|
|
static void BioResetBonus(LPCHARACTER ch,unsigned index,unsigned choice) {
|
|
if (index<1 || index>=bio_max || index>=unsigned(ch->GetQuestFlag("bio.level")) ||
|
|
!bio_data[index][14] || choice>3 || !bio_data[index][6+choice*2]) return;
|
|
char flag[40];snprintf(flag,sizeof(flag),"bio.bonus%u",index);
|
|
int old=ch->GetQuestFlag(flag)-1;
|
|
if(old<0 || old>3 || old==int(choice)) return;
|
|
if(ch->CountSpecifyItem(70028)<1) {ch->ChatPacket(CHAT_TYPE_COMMAND,"BioNotice reset_item");return;}
|
|
unsigned oldPoint=bio_data[index][6+old*2];
|
|
CAffect* previous=ch->FindAffect(AFFECT_COLLECT,oldPoint);
|
|
// Missing persisted rewards must not create a new bonus through a reset request.
|
|
if(!previous || previous->lApplyValue<int(bio_data[index][7+old*2])) return;
|
|
int remaining=previous->lApplyValue-bio_data[index][7+old*2];
|
|
ch->RemoveAffect(previous);
|
|
if(remaining)ch->AddAffect(AFFECT_COLLECT,oldPoint,remaining,AFF_NONE,INFINITE_AFFECT_DURATION,0,false);
|
|
unsigned point=bio_data[index][6+choice*2];
|
|
int value=bio_data[index][7+choice*2];
|
|
CAffect* existing=ch->FindAffect(AFFECT_COLLECT,point);
|
|
if(existing) {value+=existing->lApplyValue;ch->RemoveAffect(existing);}
|
|
ch->RemoveSpecifyItem(70028,1);
|
|
ch->AddAffect(AFFECT_COLLECT,point,value,AFF_NONE,INFINITE_AFFECT_DURATION,0,false);
|
|
ch->SetQuestFlag(flag,choice+1);
|
|
ch->ChatPacket(CHAT_TYPE_COMMAND,"BioNotice reset");
|
|
}
|
|
|
|
ACMD(do_port_biolog) {
|
|
quest::PC* pc=quest::CQuestManager::instance().GetPCForce(ch->GetPlayerID());
|
|
if (!pc || !pc->IsLoaded()) return;
|
|
std::vector<std::string> args;BioSplitArgument(argument,args);
|
|
if (args.size()==2 && args[1]=="status") {SendBioState(ch);return;}
|
|
if (pc->IsRunning() || !ch->CanHandleItem() || ch->IsDead() || ch->IsStun() || ch->IsWarping() ||
|
|
ch->GetExchange() || ch->GetShop() || ch->GetMyShop() || ch->IsOpenSafebox() || ch->IsCubeOpen()) {
|
|
ch->ChatPacket(CHAT_TYPE_COMMAND,"BioNotice busy"); return;
|
|
}
|
|
if(args.size()==3 && args[1]=="buy") {
|
|
unsigned index=999;std::istringstream parser(args[2]);char extra;
|
|
if((parser>>index) && !(parser>>extra)) BioShopBuy(ch,index);
|
|
SendBioState(ch);return;
|
|
}
|
|
if(args.size()==4 && args[1]=="reset") {
|
|
unsigned index=999,choice=999;char extra;
|
|
std::istringstream a(args[2]),b(args[3]);
|
|
if((a>>index) && !(a>>extra) && (b>>choice) && !(b>>extra)) BioResetBonus(ch,index,choice);
|
|
SendBioState(ch);return;
|
|
}
|
|
int stage=ch->GetQuestFlag("bio.level");
|
|
if (stage<1 || stage>=int(bio_max)) return;
|
|
// Reject forged booleans/empty reward choices before AVA2's byte parsing can wrap them.
|
|
if (args.size()==4 && args[1]=="mission" && (args[2]=="0" || args[2]=="1") && (args[3]=="0" || args[3]=="1")) {
|
|
do_ava2_bio(ch,argument,cmd,subcmd);
|
|
} else if (args.size()==3 && args[1]=="gift" && args[2].size()==1 && args[2][0]>='0' && args[2][0]<='3') {
|
|
unsigned choice=args[2][0]-'0';
|
|
if (!bio_data[stage][14] || !bio_data[stage][6+choice*2]) return;
|
|
do_ava2_bio(ch,argument,cmd,subcmd);
|
|
} else return;
|
|
SendBioState(ch);
|
|
}
|