00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pent_include.h"
00020
00021 #include "GrantPeaceProcess.h"
00022 #include "World.h"
00023 #include "Actor.h"
00024 #include "CurrentMap.h"
00025 #include "TargetGump.h"
00026 #include "WeaponInfo.h"
00027 #include "PaletteFaderProcess.h"
00028 #include "UCList.h"
00029 #include "LoopScript.h"
00030 #include "Direction.h"
00031 #include "Kernel.h"
00032 #include "GumpNotifyProcess.h"
00033 #include "MainActor.h"
00034 #include "SpriteProcess.h"
00035 #include "AudioProcess.h"
00036 #include "getObject.h"
00037
00038 #include "IDataSource.h"
00039 #include "ODataSource.h"
00040
00041
00042 DEFINE_RUNTIME_CLASSTYPE_CODE(GrantPeaceProcess,Process);
00043
00044 GrantPeaceProcess::GrantPeaceProcess() : Process()
00045 {
00046
00047 }
00048
00049 GrantPeaceProcess::GrantPeaceProcess(Actor* caster)
00050 {
00051 assert(caster);
00052 item_num = caster->getObjId();
00053
00054 type = 0x21d;
00055
00056 havetarget = false;
00057 }
00058
00059 bool GrantPeaceProcess::run(const uint32 )
00060 {
00061 Actor* caster = getActor(item_num);
00062 if (!caster) {
00063 terminate();
00064 return false;
00065 }
00066
00067 if (!havetarget) {
00068 TargetGump* targetgump = new TargetGump(0, 0);
00069 targetgump->InitGump(0);
00070
00071 waitFor(targetgump->GetNotifyProcess()->getPid());
00072
00073 havetarget = true;
00074
00075 return false;
00076 }
00077
00078
00079 ObjId targetid = static_cast<ObjId>(result);
00080 Actor* target = getActor(targetid);
00081
00082 if (targetid == 1 || !target ) {
00083
00084 terminate();
00085 return false;
00086 }
00087
00088 bool hit = false;
00089
00090 if (target->getDefenseType() & WeaponInfo::DMG_UNDEAD) {
00091
00092
00093
00094 CurrentMap* currentmap = World::get_instance()->getCurrentMap();
00095 UCList KGlist(2);
00096 LOOPSCRIPT(script, LS_SHAPE_EQUAL(289));
00097 currentmap->areaSearch(&KGlist, script, sizeof(script),
00098 caster, 2048, false);
00099 bool khumash = (KGlist.getSize() > 0);
00100
00101
00102 UCList itemlist(2);
00103 LOOPSCRIPT(script2, LS_TOKEN_TRUE);
00104 currentmap->areaSearch(&itemlist, script2, sizeof(script2),
00105 caster, 768, false);
00106
00107 for (unsigned int i = 0; i < itemlist.getSize(); ++i) {
00108 Actor *t = getActor(itemlist.getuint16(i));
00109 if (!t) continue;
00110 if (t == caster) continue;
00111
00112 if (t->isDead()) continue;
00113
00114
00115 if (t->getDefenseType() & WeaponInfo::DMG_UNDEAD) {
00116 t->receiveHit(item_num, 8, target->getHP(),
00117 (WeaponInfo::DMG_MAGIC |
00118 WeaponInfo::DMG_PIERCE |
00119 WeaponInfo::DMG_FIRE));
00120 hit = true;
00121
00122 if (t->getShape() == 411 && khumash) {
00123 sint32 tx,ty,tz;
00124 t->getLocation(tx,ty,tz);
00125
00126
00127 Process *sp = new SpriteProcess(480,0,9,1,1, tx, ty, tz);
00128 Kernel::get_instance()->addProcess(sp);
00129
00130 Item* throne = getItem(KGlist.getuint16(0));
00131 if (throne) {
00132 throne->setFrame(1);
00133 }
00134 }
00135
00136 #if 0
00137
00138
00139 int dir = caster->getDirToItemCentre(*t);
00140
00141 t->hurl(((std::rand() % 5) + 5) * x_fact[dir],
00142 ((std::rand() % 5) + 5) * y_fact[dir],
00143 ((std::rand() % 5) + 5),
00144 4);
00145 #endif
00146 }
00147
00148 }
00149
00150 } else {
00151
00152
00153 if (!(target->getActorFlags() & (Actor::ACT_DEAD |
00154 Actor::ACT_IMMORTAL |
00155 Actor::ACT_INVINCIBLE)))
00156 {
00157 if (std::rand() % 10 == 0) {
00158 target->receiveHit(item_num, 8, target->getHP(),
00159 (WeaponInfo::DMG_MAGIC |
00160 WeaponInfo::DMG_PIERCE |
00161 WeaponInfo::DMG_FIRE));
00162 hit = true;
00163 }
00164 }
00165
00166 }
00167
00168
00169 if (hit) {
00170
00171
00172
00173 PaletteFaderProcess::I_lightningBolt(0, 0);
00174 int sfx;
00175 switch (std::rand() % 3) {
00176 case 0: sfx = 91; break;
00177 case 1: sfx = 94; break;
00178 default: sfx = 96; break;
00179 }
00180
00181 AudioProcess* audioproc = AudioProcess::get_instance();
00182 if (audioproc) audioproc->playSFX(sfx, 0x60, 1, 0);
00183 }
00184
00185
00186
00187 terminate();
00188
00189 return true;
00190 }
00191
00192 uint32 GrantPeaceProcess::I_castGrantPeace(const uint8* args,
00193 unsigned int )
00194 {
00195 MainActor* avatar = getMainActor();
00196
00197 GrantPeaceProcess* gpp = new GrantPeaceProcess(avatar);
00198 Kernel::get_instance()->addProcess(gpp);
00199
00200
00201 ProcId anim1 = avatar->doAnim(Animation::cast1, 8);
00202
00203
00204 ProcId anim2 = avatar->doAnim(Animation::cast3, 8);
00205 Process* anim2p = Kernel::get_instance()->getProcess(anim2);
00206
00207
00208 ProcId anim3 = avatar->doAnim(Animation::cast2, 8);
00209 Process* anim3p = Kernel::get_instance()->getProcess(anim3);
00210
00211 anim2p->waitFor(anim1);
00212 anim3p->waitFor(anim2);
00213 gpp->waitFor(anim2);
00214
00215 return 0;
00216 }
00217
00218 void GrantPeaceProcess::saveData(ODataSource* ods)
00219 {
00220 Process::saveData(ods);
00221
00222 uint8 ht = havetarget ? 1 : 0;
00223 ods->write1(ht);
00224 }
00225
00226 bool GrantPeaceProcess::loadData(IDataSource* ids, uint32 version)
00227 {
00228 if (!Process::loadData(ids, version)) return false;
00229
00230 havetarget = (ids->read1() != 0);
00231
00232 return true;
00233 }