1 /***************************************************************************
2        potionexpirationevent.cpp  -  Potion expiration event
3                              -------------------
4     begin                : Thu Apr 8 2004
5     copyright            : (C) 2004 by Gabor Torok
6     email                : cctorok@yahoo.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #include "../common/constants.h"
19 #include "potionexpirationevent.h"
20 #include "../rpg/rpglib.h"
21 #include "../render/renderlib.h"
22 #include "../item.h"
23 #include "../creature.h"
24 #include "../session.h"
25 
26 using namespace std;
27 
PotionExpirationEvent(Date currentDate,Date timeOut,Creature * c,Item * item,Session * session,int nbExecutionsToDo)28 PotionExpirationEvent::PotionExpirationEvent( Date currentDate,
29                                               Date timeOut,
30                                               Creature *c,
31                                               Item *item,
32                                               Session *session,
33                                               int nbExecutionsToDo )
34 		: Event( currentDate, timeOut, nbExecutionsToDo ) {
35 	this->creature = c;
36 	this->potionSkill = item->getRpgItem()->getPotionSkill();
37 	this->amount = item->getRpgItem()->getPotionPower();
38 	this->session = session;
39 }
40 
PotionExpirationEvent(Date currentDate,Date timeOut,Creature * c,int potionSkill,int amount,Session * session,int nbExecutionsToDo)41 PotionExpirationEvent::PotionExpirationEvent( Date currentDate,
42                                               Date timeOut,
43                                               Creature *c,
44                                               int potionSkill,
45                                               int amount,
46                                               Session *session,
47                                               int nbExecutionsToDo ) : Event( currentDate, timeOut, nbExecutionsToDo ) {
48 	this->creature = c;
49 	this->potionSkill = potionSkill;
50 	this->amount = amount;
51 	this->session = session;
52 }
53 
~PotionExpirationEvent()54 PotionExpirationEvent::~PotionExpirationEvent() {
55 }
56 
execute()57 void PotionExpirationEvent::execute() {
58 
59 	// Don't need this event anymore
60 	scheduleDeleteEvent();
61 
62 	if ( creature->getStateMod( StateMod::dead ) ) return;
63 	enum { MSG_SIZE = 255 };
64 	char msg[ MSG_SIZE ];
65 	if ( potionSkill < 0 ) {
66 		switch ( -potionSkill - 2 ) {
67 		case Constants::HP:
68 		case Constants::MP:
69 			// no-op
70 			return;
71 		case Constants::AC:
72 			creature->setBonusArmor( creature->getBonusArmor() - amount );
73 			snprintf( msg, MSG_SIZE, _( "%s feels vulnerable..." ), creature->getName() );
74 			session->getGameAdapter()->writeLogMessage( msg, Constants::MSGTYPE_STATS );
75 			creature->startEffect( Constants::EFFECT_SWIRL, ( Constants::DAMAGE_DURATION * 4 ) );
76 			return;
77 		default:
78 			cerr << "Implement me! (other potion skill boost)" << endl;
79 			return;
80 		}
81 	} else {
82 		creature->setSkillBonus( potionSkill,
83 		                         creature->getSkillBonus( potionSkill ) -
84 		                         amount );
85 		// recalcAggregateValues();
86 		snprintf( msg, MSG_SIZE,  _( "%s feels a loss of contentment." ), creature->getName() );
87 		session->getGameAdapter()->writeLogMessage( msg, Constants::MSGTYPE_STATS );
88 		creature->startEffect( Constants::EFFECT_SWIRL, ( Constants::DAMAGE_DURATION * 4 ) );
89 	}
90 }
91 
doesReferenceCreature(Creature * creature)92 bool PotionExpirationEvent::doesReferenceCreature( Creature *creature ) {
93 	return( this->creature == creature );
94 }
95 
96