Erwan
- Reward system in Story mode (currently, either credits or random set) - Rules now accept for player 2 to start (see story mode "block" stage) - Story mode now has an autosave/autoload mechanism. This is for convenience but also to prevent people from abusing the reward mechanism too easily. - possibility to choose an avatar for both players through the rules (see example in story mode)
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,11 @@
|
||||
[INIT]
|
||||
mode=mtg
|
||||
player=2
|
||||
phase=combat_attackers
|
||||
[PLAYER1]
|
||||
inplay:grizzly bears
|
||||
life:1
|
||||
auto=@movedTo(*|graveyard): winGame controller
|
||||
[PLAYER2]
|
||||
inplay:raging goblin
|
||||
auto=lord(goblin) mustattack
|
||||
@@ -10,7 +10,8 @@
|
||||
<text>in my life, enough to understand the basics of their craft...</text>
|
||||
|
||||
<answer goto="tap_mana_intro" align="center" x="0.30" font="1">I want to know more</answer>
|
||||
<answer goto="tap_mana_intro" x="0.80" y="-1">Take me back to the menu</answer>
|
||||
<answer goto="End" x="0.80" y="-1">Take me back to the menu</answer>
|
||||
<answer goto="block">Continue</answer>
|
||||
</page>
|
||||
|
||||
<page id="tap_mana_intro">
|
||||
@@ -138,13 +139,48 @@
|
||||
<text>- Block your opponent's attacking creatures during the "blockers" phase of his turn.</text>
|
||||
<text>There are lots of other phases but we'll discuss them later</text>
|
||||
|
||||
<answer goto="block_1">Continue</answer>
|
||||
</page>
|
||||
|
||||
<page id="block_1">
|
||||
<type>dialog</type>
|
||||
<title>blocking</title>
|
||||
<text>Now let's block!</text>
|
||||
<text>Your opponent will attack you with one of its creatures.</text>
|
||||
<text>When comes the "blockers" phase, I want you to click on your own creature</text>
|
||||
<text>to block his attack</text>
|
||||
<text>If you don't, his creature will kill you</text>
|
||||
|
||||
<answer goto="block">Continue</answer>
|
||||
</page>
|
||||
|
||||
<page id="block">
|
||||
<type>duel</type>
|
||||
<onwin>block_ok</onwin>
|
||||
<onlose>block_try_again</onlose>
|
||||
</page>
|
||||
|
||||
<page id="block_try_again">
|
||||
<type>dialog</type>
|
||||
<title>Oh well</title>
|
||||
<text>Your opponent killed you</text>
|
||||
<text>Be sure to click once on your grizzly bears when the opponent attacks you</text>
|
||||
<answer goto="block">Let's try again!</answer>
|
||||
</page>
|
||||
|
||||
<page id="block_ok">
|
||||
<type>dialog</type>
|
||||
<title>Great!</title>
|
||||
<text>You now understand the basics of the combat phase</text>
|
||||
<answer goto="End">Continue</answer>
|
||||
</page>
|
||||
|
||||
<page id="End">
|
||||
<type>End</type>
|
||||
<title>CONGRATULATIONS!</title>
|
||||
<text>This is the end of this tutorial,</text>
|
||||
<text>now time for you to fight some real ennemies!</text>
|
||||
<text>This is the end of this tutorial.</text>
|
||||
<reward type="credits" value="1000">Here's a 1000 credits coupon to get you started, come and visit my shop!</reward>
|
||||
<reward type="unlockset" >And I'm nice, I unlocked ${SET} for you!</reward>
|
||||
<text>Now time for you to fight some real ennemies!</text>
|
||||
<text>Click on the action button to go back to the main menu</text>
|
||||
</page>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[INIT]
|
||||
mode=mtg
|
||||
[PLAYER1]
|
||||
avatar:campaigns/01.Where it all begins/_gfx/willow.jpg
|
||||
inplay:forest
|
||||
auto=@tapped(land|myinplay):wingame controller
|
||||
auto=@next combatbegins:wingame opponent
|
||||
@@ -29,7 +29,6 @@ private:
|
||||
int isMomirUnlocked();
|
||||
int isEvilTwinUnlocked();
|
||||
int isRandomDeckUnlocked();
|
||||
int unlockRandomSet();
|
||||
public:
|
||||
int value;
|
||||
Player * p1, *p2;
|
||||
@@ -44,6 +43,8 @@ public:
|
||||
~Credits();
|
||||
void compute(Player * _p1, Player * _p2, GameApp * _app);
|
||||
void Render();
|
||||
static int unlockRandomSet(bool force = false);
|
||||
static int addCreditBonus(int value);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,10 +30,10 @@ class GameObserver{
|
||||
queue<WEvent *> eventsQueue;
|
||||
|
||||
int nbPlayers;
|
||||
int currentPlayerId;
|
||||
int untap(MTGCardInstance * card);
|
||||
|
||||
public:
|
||||
int currentPlayerId;
|
||||
CombatStep combatStep;
|
||||
int turn;
|
||||
int forceShuffleLibraries();
|
||||
|
||||
@@ -26,8 +26,8 @@ private:
|
||||
list<Phase *> ring;
|
||||
list<Phase *>::iterator current;
|
||||
Phase * getCurrentPhase();
|
||||
Phase * forward();
|
||||
Phase * goToPhase(int id, Player * player);
|
||||
Phase * forward(bool sendEvents = true);
|
||||
Phase * goToPhase(int id, Player * player,bool sendEvents = true);
|
||||
PhaseRing(Player* players[], int nbPlayers=2);
|
||||
~PhaseRing();
|
||||
int addPhase(Phase * phase);
|
||||
|
||||
@@ -40,6 +40,7 @@ class Player: public Damageable{
|
||||
|
||||
virtual int receiveEvent(WEvent * event){return 0;};
|
||||
virtual void Render(){};
|
||||
void loadAvatar(string file);
|
||||
};
|
||||
|
||||
class HumanPlayer: public Player{
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
|
||||
class PlayerData{
|
||||
protected:
|
||||
void init();
|
||||
public:
|
||||
int credits;
|
||||
map<string,string>storySaves;
|
||||
MTGDeck * collection;
|
||||
TaskList * taskList;
|
||||
PlayerData(); //This doesn't init the collection, do not use it to manipulate the player's collection
|
||||
PlayerData(MTGAllCards * allcards);
|
||||
~PlayerData();
|
||||
int save();
|
||||
|
||||
@@ -25,6 +25,7 @@ class RulesPlayerData{
|
||||
public:
|
||||
vector <string> extraRules;
|
||||
int life;
|
||||
string avatar;
|
||||
ManaCost * manapool;
|
||||
RulesPlayerZone zones[5];
|
||||
RulesPlayerData();
|
||||
@@ -36,6 +37,7 @@ class RulesPlayerData{
|
||||
class RulesState{
|
||||
public:
|
||||
int phase;
|
||||
int player;
|
||||
void parsePlayerState(int playerId, string s);
|
||||
RulesState();
|
||||
RulesPlayerData playerData[2];
|
||||
|
||||
@@ -45,6 +45,25 @@ StoryImage(string img, float mX, float mY);
|
||||
float getHeight();
|
||||
};
|
||||
|
||||
class StoryReward:public StoryText {
|
||||
public:
|
||||
enum {
|
||||
STORY_REWARD_CREDITS,
|
||||
STORY_REWARD_SET
|
||||
};
|
||||
|
||||
int rewardDone;
|
||||
string value;
|
||||
int type;
|
||||
|
||||
StoryReward(string _type, string _value, string text, float _mX, float _mY, string align = "center", int font = 0, int id = 0);
|
||||
void Update(float dt);
|
||||
void Render();
|
||||
|
||||
static bool rewardSoundPlayed;
|
||||
static bool rewardsEnabled;
|
||||
};
|
||||
|
||||
class StoryChoice:public StoryText {
|
||||
public:
|
||||
string pageId;
|
||||
@@ -110,6 +129,7 @@ private:
|
||||
map<string,StoryPage *>pages;
|
||||
bool parse(string filename);
|
||||
StoryPage * loadPage(TiXmlElement* element);
|
||||
bool _gotoPage(string id);
|
||||
public:
|
||||
string currentPageId;
|
||||
string folder;
|
||||
@@ -117,6 +137,7 @@ public:
|
||||
~StoryFlow();
|
||||
|
||||
bool gotoPage(string id);
|
||||
bool loadPageId(string id);
|
||||
void Update(float dt);
|
||||
void Render();
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
|
||||
p1 = _p1;
|
||||
p2 = _p2;
|
||||
app = _app;
|
||||
showMsg = (WRand() % 5);
|
||||
showMsg = (WRand() % 3);
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
if (!g->turn) return;
|
||||
PlayerData * playerdata = NEW PlayerData(app->collection);
|
||||
@@ -126,18 +126,17 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
|
||||
}else if((unlocked = unlockRandomSet())) {
|
||||
unlockedTex = resources.RetrieveTexture("set_unlocked.png");
|
||||
unlockedQuad = resources.RetrieveQuad("set_unlocked.png", 2, 2, 396, 96);
|
||||
goa = (GameOptionAward*) &options[Options::optionSet(unlocked - 1)];
|
||||
goa->giveAward();
|
||||
options.save();
|
||||
MTGSetInfo * si = setlist.getInfo(unlocked - 1);
|
||||
if(si) unlockedString = si->getName(); //Show the set's pretty name for unlocks.
|
||||
}
|
||||
|
||||
if (unlocked && options[Options::SFXVOLUME].number > 0){
|
||||
JSample * sample = resources.RetrieveSample("bonus.wav");
|
||||
if (sample){
|
||||
JSoundSystem::GetInstance()->PlaySample(sample);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
vector<CreditBonus *>::iterator it;
|
||||
@@ -283,11 +282,36 @@ int Credits::isRandomDeckUnlocked(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Credits::unlockRandomSet(){
|
||||
int Credits::addCreditBonus(int value){
|
||||
PlayerData * playerdata = NEW PlayerData();
|
||||
playerdata->credits += value;
|
||||
playerdata->save();
|
||||
SAFE_DELETE(playerdata);
|
||||
return value;
|
||||
}
|
||||
|
||||
int Credits::unlockRandomSet(bool force){
|
||||
int setId = WRand() % setlist.size();
|
||||
|
||||
if (force) {
|
||||
int init = setId;
|
||||
boolean found = false;
|
||||
do {
|
||||
if (1 != options[Options::optionSet(setId)].number)
|
||||
found = true;
|
||||
else {
|
||||
setId++;
|
||||
if (setId == setlist.size())
|
||||
setId = 0;
|
||||
}
|
||||
} while (setId != init && !found);
|
||||
}
|
||||
|
||||
if (1 == options[Options::optionSet(setId)].number)
|
||||
return 0;
|
||||
|
||||
GameOptionAward* goa = (GameOptionAward*) &options[Options::optionSet(setId)];
|
||||
goa->giveAward();
|
||||
options.save();
|
||||
return setId + 1; //We add 1 here to show success/failure. Be sure to subtract later.
|
||||
}
|
||||
|
||||
@@ -193,12 +193,14 @@ void GameObserver::startGame(Rules * rules){
|
||||
mLayers = NEW DuelLayers();
|
||||
mLayers->init();
|
||||
|
||||
currentPlayerId = 0;
|
||||
currentPlayer = players[0];
|
||||
currentActionPlayer = currentPlayer;
|
||||
phaseRing = NEW PhaseRing(players,nbPlayers);
|
||||
if (rules)
|
||||
rules->initGame();
|
||||
|
||||
|
||||
//Preload images from hand
|
||||
if (!players[0]->isAI()){
|
||||
for (int i=0; i< players[0]->game->hand->nb_cards; i++){
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
static const char* GAME_VERSION = "WTH?! 0.11.1 - by wololo";
|
||||
|
||||
#define DEFAULT_ANGLE_MULTIPLIER 0.4
|
||||
#define DEFAULT_ANGLE_MULTIPLIER 0.4f
|
||||
#define MAX_ANGLE_MULTIPLIER (3*M_PI)
|
||||
#define MIN_ANGLE_MULTIPLIER 0.4
|
||||
#define MIN_ANGLE_MULTIPLIER 0.4f
|
||||
static const double STEP_ANGLE_MULTIPLIER = 0.0002;
|
||||
|
||||
|
||||
|
||||
@@ -76,9 +76,7 @@ void GameStateStory::Update(float dt) {
|
||||
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
|
||||
}
|
||||
}
|
||||
else {
|
||||
flow->Update(dt);
|
||||
}
|
||||
flow->Update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,30 +73,32 @@ Phase * PhaseRing::getCurrentPhase(){
|
||||
return *current;
|
||||
}
|
||||
|
||||
Phase * PhaseRing::forward(){
|
||||
Phase * PhaseRing::forward(bool sendEvents){
|
||||
Phase * cPhaseOld = *current;
|
||||
if (current != ring.end()) current++;
|
||||
if (current == ring.end()) current = ring.begin();
|
||||
|
||||
//Warn the layers about the phase Change
|
||||
WEvent * e = NEW WEventPhaseChange(cPhaseOld, *current);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
//delete e;
|
||||
if (sendEvents) {
|
||||
//Warn the layers about the phase Change
|
||||
WEvent * e = NEW WEventPhaseChange(cPhaseOld, *current);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
}
|
||||
|
||||
return *current;
|
||||
}
|
||||
|
||||
Phase * PhaseRing::goToPhase(int id, Player * player){
|
||||
Phase * PhaseRing::goToPhase(int id, Player * player, bool sendEvents){
|
||||
Phase * currentPhase = *current;
|
||||
while(currentPhase->id !=id || currentPhase->player != player){ //Dangerous, risk for inifinte loop !
|
||||
#ifdef WIN32
|
||||
OutputDebugString("goto");
|
||||
#endif
|
||||
currentPhase = forward();
|
||||
currentPhase = forward(sendEvents);
|
||||
}
|
||||
return currentPhase;
|
||||
}
|
||||
|
||||
|
||||
int PhaseRing::addPhase(Phase * phase){
|
||||
ring.push_back(phase);
|
||||
return 1;
|
||||
|
||||
@@ -29,6 +29,19 @@ Player::~Player(){
|
||||
mAvatarTex = NULL;
|
||||
}
|
||||
|
||||
void Player::loadAvatar(string file){
|
||||
if (mAvatarTex) {
|
||||
resources.Release(mAvatarTex);
|
||||
mAvatar = NULL;
|
||||
mAvatarTex = NULL;
|
||||
}
|
||||
mAvatarTex = resources.RetrieveTexture(file,RETRIEVE_LOCK,TEXTURE_SUB_AVATAR);
|
||||
if (mAvatarTex)
|
||||
mAvatar = resources.RetrieveQuad(file,0,0,35,50,"playerAvatar",RETRIEVE_NORMAL,TEXTURE_SUB_AVATAR);
|
||||
else
|
||||
mAvatar = NULL;
|
||||
}
|
||||
|
||||
const string Player::getDisplayName() const {
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
if (this == g->players[0]) return "Player 1";
|
||||
@@ -58,11 +71,7 @@ Player * Player::opponent(){
|
||||
}
|
||||
|
||||
HumanPlayer::HumanPlayer(MTGPlayerCards * deck, string file, string fileSmall) : Player(deck, file, fileSmall) {
|
||||
mAvatarTex = resources.RetrieveTexture("avatar.jpg",RETRIEVE_LOCK,TEXTURE_SUB_AVATAR);
|
||||
if (mAvatarTex)
|
||||
mAvatar = resources.RetrieveQuad("avatar.jpg",0,0,35,50,"playerAvatar",RETRIEVE_NORMAL,TEXTURE_SUB_AVATAR);
|
||||
else
|
||||
mAvatar = NULL;
|
||||
loadAvatar("avatar.jpg");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,19 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
PlayerData::PlayerData(){
|
||||
init();
|
||||
}
|
||||
PlayerData::PlayerData(MTGAllCards * allcards){
|
||||
init();
|
||||
|
||||
//COLLECTION
|
||||
if (allcards) collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), allcards);
|
||||
}
|
||||
|
||||
void PlayerData::init() {
|
||||
collection = NULL;
|
||||
|
||||
//CREDITS
|
||||
credits = 3000; //Default value
|
||||
|
||||
@@ -17,23 +29,50 @@ PlayerData::PlayerData(MTGAllCards * allcards){
|
||||
}else{
|
||||
//TODO error management
|
||||
}
|
||||
|
||||
//Story Saves
|
||||
while(std::getline(file,s)){
|
||||
if (!s.size())
|
||||
continue;
|
||||
if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files
|
||||
if (s.size() && s[0] == '#')
|
||||
continue;
|
||||
size_t i = s.find_first_of("=");
|
||||
if (i == string::npos)
|
||||
continue;
|
||||
|
||||
string key = s.substr(0,i);
|
||||
string value = s.substr(i+1);
|
||||
if (key.size() < 3)
|
||||
continue;
|
||||
|
||||
if(key[0] != 's')
|
||||
continue;
|
||||
key = key.substr(2);
|
||||
storySaves[key]=value;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
//COLLECTION
|
||||
collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), allcards);
|
||||
taskList = NEW TaskList(options.profileFile(PLAYER_TASKS).c_str());
|
||||
}
|
||||
|
||||
int PlayerData::save(){
|
||||
std::ofstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
|
||||
char writer[64];
|
||||
char writer[512];
|
||||
if (file){
|
||||
sprintf(writer,"%i\n", credits);
|
||||
file<<writer;
|
||||
|
||||
//Story Saves
|
||||
for (map<string,string>::iterator it =storySaves.begin(); it !=storySaves.end(); ++it){
|
||||
sprintf(writer,"s %s=%s\n", it->first.c_str(),it->second.c_str());
|
||||
file << writer;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
collection->save();
|
||||
if (collection) collection->save();
|
||||
taskList->save();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ MTGCardInstance * Rules::getCardByMTGId(int mtgid){
|
||||
RulesPlayerData::RulesPlayerData(){
|
||||
life = 20;
|
||||
manapool = NEW ManaCost();
|
||||
avatar = "";
|
||||
}
|
||||
|
||||
RulesPlayerData::~RulesPlayerData(){
|
||||
@@ -55,7 +56,7 @@ void RulesPlayerZone::add(int cardId){
|
||||
|
||||
RulesState::RulesState(){
|
||||
phase = Constants::MTG_PHASE_FIRSTMAIN;
|
||||
|
||||
player = 0;
|
||||
}
|
||||
|
||||
void RulesState::parsePlayerState(int playerId, string s){
|
||||
@@ -76,6 +77,9 @@ void RulesState::parsePlayerState(int playerId, string s){
|
||||
}else if(areaS.compare("life") == 0){
|
||||
playerData[playerId].life = atoi((s.substr(limiter+1)).c_str());
|
||||
return;
|
||||
}else if(areaS.compare("avatar") == 0){
|
||||
playerData[playerId].avatar = s.substr(limiter+1);
|
||||
return;
|
||||
}else if(areaS.compare("manapool") == 0){
|
||||
SAFE_DELETE(playerData[playerId].manapool);
|
||||
playerData[playerId].manapool = ManaCost::parseManaCost(s.substr(limiter+1));
|
||||
@@ -256,12 +260,23 @@ void Rules::initGame(){
|
||||
//Put the GameObserver in the initial state
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
OutputDebugString("RULES Init Game\n");
|
||||
g->phaseRing->goToPhase(initState.phase, g->players[0]);
|
||||
|
||||
//Set the current player/phase
|
||||
g->currentPlayer = g->players[initState.player];
|
||||
g->currentActionPlayer = g->currentPlayer;
|
||||
g->currentPlayerId = initState.player;
|
||||
g->phaseRing->goToPhase(0, g->currentPlayer, false);
|
||||
g->phaseRing->goToPhase(initState.phase, g->currentPlayer);
|
||||
g->currentGamePhase = initState.phase;
|
||||
|
||||
|
||||
for (int i = 0; i < 2; i++){
|
||||
Player * p = g->players[i];
|
||||
p->life = initState.playerData[i].life;
|
||||
p->getManaPool()->copy(initState.playerData[i].manapool);
|
||||
if (initState.playerData[i].avatar.size()) {
|
||||
p->loadAvatar(initState.playerData[i].avatar);
|
||||
}
|
||||
MTGGameZone * playerZones[] = {p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay};
|
||||
for (int j = 0; j < 4; j++){
|
||||
MTGGameZone * zone = playerZones[j];
|
||||
@@ -371,6 +386,8 @@ int Rules::load(string _filename){
|
||||
extraRules.push_back(s.substr(5));
|
||||
}else if (s.find("mode=") == 0) {
|
||||
gamemode = strToGameMode(s.substr(5));
|
||||
}else if (s.find("player=") == 0) {
|
||||
initState.player = atoi(s.substr(7).c_str())-1;
|
||||
}else{
|
||||
initState.phase = PhaseRing::phaseStrToInt(s);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "../include/WResourceManager.h"
|
||||
#include "../include/AIPlayer.h"
|
||||
#include "../include/Rules.h"
|
||||
#include "../include/Credits.h"
|
||||
#include "../include/PlayerData.h"
|
||||
#include <JLBFont.h>
|
||||
#include <JGE.h>
|
||||
#include <JFileSystem.h>
|
||||
@@ -14,6 +16,8 @@
|
||||
|
||||
float StoryDialog::currentY = 2;
|
||||
float StoryDialog::previousY = 2;
|
||||
bool StoryReward::rewardSoundPlayed = false;
|
||||
bool StoryReward::rewardsEnabled = true;
|
||||
|
||||
StoryDialogElement::StoryDialogElement(float x, float y, int id): JGuiObject(id), mX(x),mY(y) {
|
||||
}
|
||||
@@ -49,6 +53,70 @@ float StoryText::getHeight() {
|
||||
//Nothing for now
|
||||
}
|
||||
|
||||
|
||||
StoryReward::StoryReward(string _type, string _value, string text, float _mX, float _mY, string _align, int _font, int id):StoryText(text,_mX,_mY, _align, _font, id) {
|
||||
type = STORY_REWARD_CREDITS;
|
||||
if (_type.compare("unlockset") == 0) {
|
||||
type = STORY_REWARD_SET;
|
||||
}
|
||||
value = _value;
|
||||
rewardDone = 0;
|
||||
|
||||
}
|
||||
|
||||
void StoryReward::Render(){
|
||||
if (rewardDone <=0)
|
||||
return;
|
||||
StoryText::Render();
|
||||
}
|
||||
|
||||
void StoryReward::Update(float dt){
|
||||
if (rewardDone)
|
||||
return;
|
||||
|
||||
int result = 0;
|
||||
|
||||
switch (type){
|
||||
case STORY_REWARD_CREDITS:
|
||||
result = Credits::addCreditBonus(atoi(value.c_str()));
|
||||
break;
|
||||
case STORY_REWARD_SET:
|
||||
{
|
||||
result = Credits::unlockRandomSet(true);
|
||||
MTGSetInfo * si = setlist.getInfo(result - 1);
|
||||
if(si) {
|
||||
string unlockedString = si->getName();
|
||||
size_t pos = text.find("${SET}");
|
||||
if (pos != string::npos) {
|
||||
text.replace(pos,pos + 6,unlockedString);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
rewardDone = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rewardsEnabled) {
|
||||
rewardDone = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rewardSoundPlayed && options[Options::SFXVOLUME].number > 0){
|
||||
JSample * sample = resources.RetrieveSample("bonus.wav");
|
||||
if (sample){
|
||||
JSoundSystem::GetInstance()->PlaySample(sample);
|
||||
}
|
||||
rewardSoundPlayed = 1;
|
||||
}
|
||||
rewardDone = 1;
|
||||
}
|
||||
|
||||
ostream& StoryText::toString(ostream& out) const
|
||||
{
|
||||
return out << "StoryText ::: text : " << text;
|
||||
@@ -90,15 +158,6 @@ StoryPage::StoryPage(StoryFlow * mParent):mParent(mParent){
|
||||
}
|
||||
|
||||
|
||||
|
||||
StoryFlow::StoryFlow(string folder): folder(folder){
|
||||
string path = "campaigns/";
|
||||
path.append(folder).append("/story.xml");
|
||||
parse(path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void StoryChoice::Render()
|
||||
{
|
||||
JLBFont * mFont = resources.GetJLBFont(font);
|
||||
@@ -182,7 +241,7 @@ void StoryDuel::init(){
|
||||
players[0] = NEW HumanPlayer(NEW MTGPlayerCards(tempDeck),deckFile,deckFileSmall);
|
||||
SAFE_DELETE(tempDeck);
|
||||
|
||||
sprintf(deckFile,"%s/ennemy_deck.txt", folder);
|
||||
sprintf(deckFile,"%s/opponent_deck.txt", folder);
|
||||
tempDeck = NEW MTGDeck(deckFile, GameApp::collection);
|
||||
sprintf(deckFileSmall, "campaign_ennemy_%s_%s", mParent->folder.c_str(), pageId.c_str());
|
||||
players[1] = NEW AIPlayerBaka(NEW MTGPlayerCards(tempDeck),deckFile,deckFileSmall,"baka.jpg");
|
||||
@@ -293,6 +352,10 @@ StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent):StoryPage(mPar
|
||||
StoryChoice * sc = NEW StoryChoice(id,text,i,x, y , align, font, (i==0));
|
||||
graphics.push_back(sc);
|
||||
Add(sc);
|
||||
}else if (strcmp(element->Value(), "reward")==0){
|
||||
string type = safeAttribute(element,"type");
|
||||
string value = safeAttribute(element,"value");
|
||||
graphics.push_back(NEW StoryReward(type, value, text,x,y,align, font));
|
||||
}else {
|
||||
//Error
|
||||
}
|
||||
@@ -330,7 +393,7 @@ void StoryDialog::Render() {
|
||||
previousY = currentY;
|
||||
for (size_t i = 0; i < graphics.size(); ++i){
|
||||
StoryDialogElement * elmt = (StoryDialogElement *)(graphics[i]);
|
||||
if (elmt == mObjects[0])
|
||||
if (mCount && elmt == mObjects[0])
|
||||
currentY += SPACE_BEFORE_CHOICES;
|
||||
RenderElement(elmt);
|
||||
}
|
||||
@@ -348,6 +411,14 @@ StoryDialog::~StoryDialog(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
StoryFlow::StoryFlow(string folder): folder(folder){
|
||||
string path = "campaigns/";
|
||||
path.append(folder).append("/story.xml");
|
||||
parse(path);
|
||||
}
|
||||
|
||||
|
||||
StoryPage * StoryFlow::loadPage(TiXmlElement* element){
|
||||
TiXmlNode* typeNode = element->FirstChild("type");
|
||||
if (!typeNode) return NULL;
|
||||
@@ -361,12 +432,28 @@ StoryPage * StoryFlow::loadPage(TiXmlElement* element){
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
bool StoryFlow::gotoPage(string id){
|
||||
bool StoryFlow::_gotoPage(string id){
|
||||
StoryReward::rewardSoundPlayed = false;
|
||||
if (pages.find(id) == pages.end()) {
|
||||
return false;
|
||||
}
|
||||
currentPageId = id;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StoryFlow::gotoPage(string id){
|
||||
StoryReward::rewardsEnabled = true;
|
||||
return _gotoPage(id);
|
||||
}
|
||||
|
||||
bool StoryFlow::loadPageId(string id) {
|
||||
StoryReward::rewardsEnabled = false;
|
||||
return _gotoPage(id);
|
||||
}
|
||||
|
||||
bool StoryFlow::parse(string path)
|
||||
{
|
||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||
@@ -399,6 +486,15 @@ bool StoryFlow::parse(string path)
|
||||
}
|
||||
}
|
||||
|
||||
//autoLoad
|
||||
PlayerData * pd = NEW PlayerData();
|
||||
map<string,string>::iterator it = pd->storySaves.find(folder);
|
||||
if (it!=pd->storySaves.end()) {
|
||||
if (it->second.compare("End") !=0)
|
||||
loadPageId(it->second);
|
||||
}
|
||||
SAFE_DELETE(pd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -417,4 +513,10 @@ StoryFlow::~StoryFlow(){
|
||||
SAFE_DELETE(i->second);
|
||||
}
|
||||
pages.clear();
|
||||
|
||||
//autoSave progress
|
||||
PlayerData * pd = NEW PlayerData();
|
||||
pd->storySaves[folder] = currentPageId;
|
||||
pd->save();
|
||||
SAFE_DELETE(pd);
|
||||
}
|
||||
|
||||
@@ -586,13 +586,17 @@ string WResourceManager::avatarFile(const string filename){
|
||||
return buf;
|
||||
|
||||
//Failure. Check graphics
|
||||
char graphdir[512];
|
||||
sprintf(graphdir,"graphics/%s",filename.c_str());
|
||||
if(fileOK(graphdir,true))
|
||||
return graphdir;
|
||||
|
||||
sprintf(buf,"graphics/%s",filename.c_str());
|
||||
if(fileOK(buf,true))
|
||||
return buf;
|
||||
|
||||
//Failure. Check raw faile.
|
||||
sprintf(buf,"%s",filename.c_str());
|
||||
if(fileOK(buf,true))
|
||||
return buf;
|
||||
|
||||
//Complete abject failure. Probably a crash...
|
||||
return graphdir;
|
||||
return "";
|
||||
}
|
||||
|
||||
string WResourceManager::cardFile(const string filename){
|
||||
|
||||
Reference in New Issue
Block a user