1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "ultima/ultima1/spells/kill_magic_missile.h"
24 #include "ultima/ultima1/game.h"
25 #include "ultima/ultima1/core/party.h"
26 #include "ultima/ultima1/core/resources.h"
27 #include "ultima/ultima1/maps/map_tile.h"
28 #include "ultima/ultima1/widgets/dungeon_monster.h"
29 #include "ultima/shared/maps/map_widget.h"
30 
31 namespace Ultima {
32 namespace Ultima1 {
33 namespace Spells {
34 
BEGIN_MESSAGE_MAP(KillMagicMIssile,Spell)35 BEGIN_MESSAGE_MAP(KillMagicMIssile, Spell)
36 	ON_MESSAGE(CharacterInputMsg)
37 END_MESSAGE_MAP()
38 
39 void KillMagicMIssile::cast(Maps::MapBase *map) {
40 	// Prompt for a direction
41 	addInfoMsg(": ", false);
42 	Shared::CInfoGetKeypress keyMsg(this);
43 	keyMsg.execute(_game);
44 }
45 
CharacterInputMsg(CCharacterInputMsg * msg)46 bool KillMagicMIssile::CharacterInputMsg(CCharacterInputMsg *msg) {
47 	Shared::Maps::Direction dir = Shared::Maps::MapWidget::directionFromKey(msg->_keyState.keycode);
48 	Character &c = *static_cast<Party *>(_game->_party);
49 
50 	if (dir == Shared::Maps::DIR_NONE) {
51 		addInfoMsg(_game->_res->NONE);
52 		_game->endOfTurn();
53 	} else {
54 		addInfoMsg(_game->_res->DIRECTION_NAMES[(int)dir - 1]);
55 		addInfoMsg(_game->_res->SPELL_PHRASES[_spellId == SPELL_MAGIC_MISSILE ? 12 : 13], false);
56 		//uint damage = _spellId == SPELL_MAGIC_MISSILE ?
57 		//	c.equippedWeapon()->getMagicDamage() : 9999;
58 
59 		if (c._class == CLASS_CLERIC || _game->getRandomNumber(1, 100) < c._wisdom) {
60 			_game->playFX(5);
61 			addInfoMsg("");
62 
63 			// TODO: Non-dungeon damage
64 			// damage(dir,  7, 3, damage, 101, "SpellEffect");
65 		} else {
66 			addInfoMsg(_game->_res->FAILED);
67 			_game->playFX(6);
68 			_game->endOfTurn();
69 		}
70 	}
71 
72 	return true;
73 }
74 
75 /*-------------------------------------------------------------------*/
76 
Kill(Ultima1Game * game,Character * c)77 Kill::Kill(Ultima1Game *game, Character *c) : KillMagicMIssile(game, c, SPELL_KILL) {
78 }
79 
dungeonCast(Maps::MapDungeon * map)80 void Kill::dungeonCast(Maps::MapDungeon *map) {
81 	Point newPos;
82 	Maps::U1MapTile tile;
83 
84 	newPos = map->getPosition() + map->getDirectionDelta();
85 	map->getTileAt(newPos, &tile);
86 
87 	Widgets::DungeonMonster *monster = dynamic_cast<Widgets::DungeonMonster *>(tile._widget);
88 	if (monster) {
89 		monster->attackMonster(5, 101, Widgets::ITS_OVER_9000);
90 		_game->endOfTurn();
91 	} else {
92 		// Failed
93 		KillMagicMIssile::dungeonCast(map);
94 	}
95 }
96 
97 /*-------------------------------------------------------------------*/
98 
MagicMissile(Ultima1Game * game,Character * c)99 MagicMissile::MagicMissile(Ultima1Game *game, Character *c) : KillMagicMIssile(game, c, SPELL_MAGIC_MISSILE) {
100 }
101 
dungeonCast(Maps::MapDungeon * map)102 void MagicMissile::dungeonCast(Maps::MapDungeon *map) {
103 	Widgets::DungeonMonster *monster = map->findCreatureInCurrentDirection();
104 
105 	if (monster) {
106 		Character *c = *static_cast<Party *>(_game->_party);
107 		uint damage = c->equippedWeapon()->getMagicDamage();
108 		monster->attackMonster(5, 101, damage);
109 	} else {
110 		KillMagicMIssile::dungeonCast(map);
111 	}
112 }
113 
114 } // End of namespace Spells
115 } // End of namespace Ultima1
116 } // End of namespace Ultima
117