aboutsummaryrefslogtreecommitdiff
path: root/src/creature.cc
blob: 7d096d3fd737efc8d3ac00ed4bd111ef4752856b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
#include "creature.hh"

#include "enums.hh"
#include "player.hh"

#include <math.h>

// TSkill REGULAR FUNCTIONS
//==============================================================================
TSkill::TSkill(int SkNr, TCreature *Master){
	this->Reset();
	this->SkNr = (uint16)SkNr;
	this->Master = Master;
}

int TSkill::Get(void){
	int Value = this->Act;
	if(Value < this->Min)
		Value = this->Min;
	Value += this->MDAct + this->DAct;
	return Value;
}

int TSkill::GetProgress(void){
	int Result = 0;
	if(this->NextLevel > this->LastLevel){
		Result = (this->Exp - this->LastLevel) * 100 / (this->NextLevel - this->LastLevel);

		// TODO(fusion): This feels too much for reporting a mostly *impossible* error.
		if(Result < 0 || Result > 100){
			error("TSkill::GetProgress: Berechnungsfehler Exp %d, Last %d, Next %d, Prozent %d.\n",
					this->Exp, this->LastLevel, this->NextLevel, Result);

			const char *MasterName = "(Unknown";
			if(this->Master != NULL){
				MasterName = this->Master->Name;
			}
			error("# Spieler %s - Skill %d\n", MasterName, this->SkNr);
			Result = 0;
		}
	}
	return Result;
}

void TSkill::Check(void){
	if(this->Act > this->Max){
		this->Act = this->Max;
	}
}

void TSkill::Change(int Amount){
	this->Set(this->Act + Amount);

	// TODO(fusion): Probably `TSkill::Check` inlined? It doesn't make a whole
	// lot of sense because `TSkill::Set` also checks the value. Maybe a custom
	// version of it does something differently?
	if(this->Act > this->Max){
		this->Act = this->Max;
	}
}

void TSkill::SetMDAct(int MDAct){
	this->MDAct = MDAct;
	if(this->SkNr == 4 && this->Master && this->Master->Type == PLAYER){
		// TODO(fusion): Same as `TSkill::Process`.
		((TPlayer*)this->Master)->CheckState();
	}
}

void TSkill::Load(int Act, int Max, int Min, int DAct, int MDAct,
		int Cycle, int MaxCycle, int Count, int MaxCount, int AddLevel,
		int Exp, int FactorPercent, int NextLevel, int Delta){
	this->Act = Act;
	this->Max = Max;
	this->Min = Min;
	this->DAct = DAct;
	this->MDAct = MDAct;
	this->Cycle = Cycle;
	this->MaxCycle = MaxCycle;
	this->Count = Count;
	this->MaxCount = MaxCount;
	this->AddLevel = AddLevel;
	this->Exp = Exp;
	this->FactorPercent = FactorPercent;
	this->NextLevel = NextLevel;
	this->Delta = Delta;

	// TODO(fusion): Shouldn't we also do the same for `NextLevel`?
	this->LastLevel = this->GetExpForLevel(Act);

	TCreature *Master = this->Master;
	if(Master && Cycle != 0){
		int SkNr = this->SkNr;
		if(SkNr >= NARRAY(Master->Skills)){
			error("TSkillBase::SetTimer: Ungueltige SkNr: %d\n", SkNr);
			return;
		}

		// TODO(fusion): I'm not entirely sure wtf is going on here.
		TSkill *Other = Master->Skills[SkNr];
		Master->DelTimer(SkNr);
		if(Other->SetTimer(Cycle, Count, MaxCount, FactorPercent)){
			Master->TimerList[Master->FirstFreeTimer] = Other;
			Master->FirstFreeTimer += 1;
		}
	}
}


void TSkill::Save(int *Act, int *Max, int *Min, int *DAct, int *MDAct,
		int *Cycle, int *MaxCycle, int *Count, int *MaxCount, int *AddLevel,
		int *Exp, int *FactorPercent, int *NextLevel, int *Delta){
	*Act = this->Act;
	*Max = this->Max;
	*Min = this->Min;
	*DAct = this->DAct;
	*MDAct = this->MDAct;
	*Cycle = this->Cycle;
	*MaxCycle = this->MaxCycle;
	*Count = this->Count;
	*MaxCount = this->MaxCount;
	*AddLevel = this->AddLevel;
	*Exp = this->Exp;
	*FactorPercent = this->FactorPercent;
	*NextLevel = this->NextLevel;
	*Delta = this->Delta;
}

// TSkill VIRTUAL FUNCTIONS
//==============================================================================
TSkill::~TSkill(void){
	if(this->Master != NULL){
		this->Master->DelTimer(this->SkNr);
	}
}

void TSkill::Set(int Value){
	if(Value > this->Max)
		Value = this->Max;
	this->Act = Value;
}

void TSkill::Increase(int Amount){
	// no-op
}

void TSkill::Decrease(int Amount){
	// no-op
}

int TSkill::GetExpForLevel(int Level){
	return 0;
}

void TSkill::Advance(int Range){
	// no-op
}

void TSkill::ChangeSkill(int FactorPercent, int Delta){
	// no-op
}

int TSkill::ProbeValue(int Max, bool Increase){
	return 0;
}

bool TSkill::Probe(int Diff, int Prob, bool Increase){
	return false;
}

bool TSkill::Process(void){
	bool Result = this->Cycle == 0;
	if(Result){
		if(this->Master && this->Master->Type == PLAYER){
			// TODO(fusion): Verify if a simple pointer cast works. Maybe `dynamic_cast`?
			((TPlayer*)this->Master)->CheckState();
		}
	}else if(this->Count <= 0){
		this->Count = this->MaxCount;
		// NOTE(fusion): `Range` should move `Cycle` towards ZERO.
		int Range = (this->Cycle < 1) ? +1 : -1;
		this->Cycle += Range;
		this->Event(Range);
	}else{
		this->Count -= 1;
	}

	return Result;
}

bool TSkill::SetTimer(int Cycle, int Count, int MaxCount, int AdditionalValue){
	this->Cycle = Cycle;
	this->Count = Count;
	this->MaxCount = MaxCount;
	if(this->Master && this->Master->Type == PLAYER){
		// TODO(fusion): Same as `TSkill::Process`.
		((TPlayer*)this->Master)->CheckState();
	}
	return true;
}

bool TSkill::DelTimer(void){
	this->Cycle = 0;
	this->Count = 0;
	this->MaxCount = 0;
	if(this->Master && this->Master->Type == PLAYER){
		// TODO(fusion): Same as `TSkill::Process`.
		((TPlayer*)this->Master)->CheckState();
	}
	return true;
}

int TSkill::TimerValue(void){
	return this->Cycle;
}

bool TSkill::Jump(int Range){
	return true;
}

void TSkill::Event(int Range){
	// no-op
}

void TSkill::Reset(void){
	this->Act = 0;
	this->Max = INT_MAX;
	this->Min = 0;
	this->DAct = 0;
	this->MDAct = 0;
	this->FactorPercent = 1000;
	this->LastLevel = 0;
	this->NextLevel = INT_MAX;
	this->Exp = 0;
	this->Delta = INT_MAX;
	this->Cycle = 0;
	this->MaxCycle = 0;
	this->Count = 0;
	this->MaxCount = 0;
	this->AddLevel = 0;
}

// TSkillLevel
//==============================================================================
TSkillLevel::~TSkillLevel(void){
	if(this->Master != NULL){
		this->Master->DelTimer(this->SkNr);
	}
}

void TSkillLevel::Increase(int Amount){
	if(Amount < 0){
		error("TSkillLevel::Increase: Amount negativ (%d).\n", Amount);
		return;
	}

	// BUG(fusion): No bounds check as in `TSkillLevel::Decrease`?

	// TODO(fusion): This could probably be an oversight but the decompiled
	// function was calling `GetExpForLevel` twice instead of using `NextLevel`
	// which makes me wonder whether `NextLevel` is properly initialized.
	int Range = 0;
	this->Exp += Amount;
	while(this->Exp >= this->NextLevel){
		this->Act += 1;
		this->LastLevel = this->NextLevel;
		this->NextLevel = this->GetExpForLevel(this->Act + 1);
		if(this->NextLevel < 0){
			// BUG(fusion): We don't check if `Master` is valid here?
			error("TSkillLevel::Increase: Skill vor Überlauf (%s, Skill %d).\n", this->Master->Name, this->SkNr);
			this->NextLevel = this->Exp;
			this->Exp -= 1000000;
			break;
		}
		Range += 1;
	}

	if(Range != 0){
		this->Jump(Range);
	}

	if(this->Master == NULL){
		error("TSkillLevel::Increase: GetMaster liefert NULL zurueck.\n");
		return;
	}

	if(this->Master->Type == PLAYER){
		SendPlayerData(this->Master->Connection);
	}
}

void TSkillLevel::Decrease(int Amount){
	if(Amount < 0){
		error("TSkillLevel::Decrease: Amount negativ (%d).\n", Amount);
		return;
	}

	// TODO(fusion): This is some weird ass comparison.
	if(Amount > this->Exp && this->Exp > 100000){
		error("TSkillLevel::Decrease: Amount zu gross(%d).\n", Amount);
		return;
	}

	if(Amount < this->Exp){
		this->Exp -= Amount;
	}else{
		this->Exp = 0;
	}

	// TODO(fusion): This could probably be an oversight but the decompiled
	// function was calling `GetExpForLevel` twice instead of using `LastLevel`
	// which makes me wonder whether `LastLevel` is properly initialized.
	int Range = 0;
	while(this->Exp < this->LastLevel){
		this->Act -= 1;
		this->NextLevel = this->LastLevel;
		this->LastLevel = this->GetExpForLevel(this->Act);
		Range -= 1;
	}

	if(Range != 0){
		this->Jump(Range);
	}

	if(this->Master == NULL){
		error("TSkillLevel::Decrease: GetMaster liefert NULL zurueck.\n");
		return;
	}

	if(this->Master->Type == PLAYER){
		SendPlayerData(this->Master->Connection);
	}
}

int TSkillLevel::GetExpForLevel(int Level){
	if(Level < 1){
		error("TSkillLevel::GetExpForLevel: Ungültiger Level %d.\n", Level);
		return 0;
	}

	if(this->Delta <= 0){
		error("TSkillLevel::GetExpForLevel: Ungültiger Delta-Wert %d.\n", this->Delta);
		return 0;
	}

	if(Level > 500){
		error("TSkillLevel::GetExpForLevel: Level=%d; Formel gegen Überlauf sichern.\n", Level);
		return -1; // TODO(fusion): Shouldn't this be 0?
	}

	return ((((Level - 6) * Level + 17) * Level - 12) / 6) * this->Delta;
}

bool TSkillLevel::Jump(int Range){
	if(this->Master == NULL){
		error("TSkillLevel::Jump: GetMaster liefert NULL zurueck!\n");
		return false;
	}

	this->Master->Skills[SKILL_HITPOINTS   ]->Advance(Range);
	this->Master->Skills[SKILL_MANA        ]->Advance(Range);
	this->Master->Skills[SKILL_GO_STRENGTH ]->Advance(Range);
	this->Master->Skills[SKILL_CARRY_WEIGHT]->Advance(Range);

	AnnounceChangedCreature(this->Master->ID, 4);
	this->Master->Combat.CheckCombatValues();

	if(this->Master->Type == PLAYER){
		int ToLevel = this->Get();
		int FromLevel = ToLevel - Range;
		if(Range > 0){
			SendMessage(this->Master->Connection, TALK_EVENT_MESSAGE,
					"You advanced from Level %d to Level %d.", FromLevel, ToLevel);
		}else if(Range < 0){
			SendMessage(this->Master->Connection, TALK_EVENT_MESSAGE,
					"You were downgraded from Level %d to Level %d.", FromLevel, ToLevel);
		}
	}

	return true;
}

// TSkillProbe
//==============================================================================
void TSkillProbe::Increase(int Amount){
	if(Amount < 0){
		error("TSkillProbe::Increase: Amount negativ (%d).\n", Amount);
		return;
	}

	int OldProgress = this->GetProgress();

	// TODO(fusion): This could probably be an oversight but the decompiled
	// function was calling `GetExpForLevel` twice instead of using `NextLevel`
	// which makes me wonder whether `NextLevel` is properly initialized.
	int Range = 0;
	this->Exp += Amount;
	while(this->Exp >= this->NextLevel){
		this->Act += 1;
		this->LastLevel = this->NextLevel;
		this->NextLevel = this->GetExpForLevel(this->Act + 1);
		if(this->NextLevel < 0){
			// BUG(fusion): We don't check if `Master` is valid here?
			error("TSkillProbe::Increase: Skill vor Überlauf (%s, Skill %d).\n", this->Master->Name, this->SkNr);
			this->NextLevel = this->Exp;
			this->Exp -= 1000;
			break;
		}
		Range += 1;
	}

	if(Range != 0){
		this->Jump(Range);
	}else{
		TCreature *Master = this->Master;
		if(Master && Master->Type == PLAYER){
			int NewProgress = this->GetProgress();
			if(NewProgress != OldProgress){
				if(this->SkNr == SKILL_MAGIC_LEVEL){
					SendPlayerData(Master->Connection);
				}else{
					SendPlayerSkills(Master->Connection);
				}
			}
		}
	}
}

void TSkillProbe::Decrease(int Amount){
	if(Amount < 0){
		error("TSkillProbe::Decrease: Amount negativ (%d).\n", Amount);
		return;
	}

	int OldProgress = this->GetProgress();

	if(Amount < this->Exp){
		this->Exp -= Amount;
	}else{
		this->Exp = 0;
	}

	// TODO(fusion): This could probably be an oversight but the decompiled
	// function was calling `GetExpForLevel` twice instead of using `LastLevel`
	// which makes me wonder whether `LastLevel` is properly initialized.
	int Range = 0;
	while(this->Exp < this->LastLevel && this->Act > this->Min){
		this->Act -= 1;
		this->NextLevel = this->LastLevel;
		this->LastLevel = this->GetExpForLevel(this->Act);
		Range -= 1;
	}

	if(Range != 0){
		this->Jump(Range);
	}else{
		TCreature *Master = this->Master;
		if(Master && Master->Type == PLAYER){
			int NewProgress = this->GetProgress();
			if(NewProgress != OldProgress){
				if(this->SkNr == SKILL_MAGIC_LEVEL){
					SendPlayerData(Master->Connection);
				}else{
					SendPlayerSkills(Master->Connection);
				}
			}
		}
	}
}

int TSkillProbe::GetExpForLevel(int Level){
	if(Level < 0 || Level < this->Min){
		error("TSkillProbe::GetExpForLevel: Ungültiger Level %d.\n", Level);
		return 0;
	}

	if(this->Delta <= 0){
		error("TSkillProbe::GetExpForLevel: Ungültiger Delta-Wert %d.\n", this->Delta);
		return 0;
	}

	// TODO(fusion): This part of the decompiled code was a bit weird. I had to
	// look into the disassembly to figure the string parameter of `error` below
	// and it is weird that we keep going even with invalid values of `FactorPercent`.
	int FactorPercent = this->FactorPercent;
	if(FactorPercent < 1000){
		const char *MasterName = "---";
		if(this->Master != NULL){
			MasterName = this->Master->Name;
		}
		error("TSkillProbe::GetExpForLevel: Ungültiger FactorPercent-Wert %d bei %s.\n", FactorPercent, MasterName);
	}

	if(FactorPercent < 1050){
		error("TSkillProbe::GetExpForLevel: Ungültiger FactorPercent-Wert %d. Rechne mit 1000 weiter.\n", FactorPercent);
		return (Level - this->Min) * this->Delta;
	}

	double Base = (double)FactorPercent / 1000.0;
	double Power = pow(Base, (double)(Level - this->Min));
	double Result = (double)this->Delta * ((Power - 1.0) / (Base - 1.0));
	return (int)Result;
}

void TSkillProbe::ChangeSkill(int FactorPercent, int Delta){
	double Progress = 0.0;
	if(this->LastLevel < this->NextLevel){
		Progress = (double)(this->Exp - this->LastLevel)
				/ (double)(this->NextLevel - this->LastLevel);
	}

	double Base = (double)FactorPercent / 1000.0;

	// NOTE(fusion): Similar to `this->GetExpForLevel(this->Act)` but inlined?
	double LastLevelPower = pow(Base, (double)(this->Act - this->Min));
	double LastLevel = (double)Delta * ((LastLevelPower - 1.0) / (Base - 1.0));

	// NOTE(fusion): Similar to `this->GetExpForLevel(this->Act + 1)` but inlined?
	double NextLevelPower = pow(Base, (double)(this->Act - this->Min + 1));
	double NextLevel = (double)Delta * ((NextLevelPower - 1.0) / (Base - 1.0));

	// NOTE(fusion): Renormalize experience.
	double Exp = LastLevel + Progress * (NextLevel - LastLevel);

	this->FactorPercent = FactorPercent;
	this->LastLevel = (int)LastLevel;
	this->NextLevel = (int)NextLevel;
	this->Delta = Delta;
	this->Exp = (int)Exp;

	TCreature *Master = this->Master;
	if(Master != NULL && Master->Type == PLAYER){
		if(this->SkNr == SKILL_MAGIC_LEVEL){
			SendPlayerData(Master->Connection);
		}else{
			SendPlayerSkills(Master->Connection);
		}
	}
}

int TSkillProbe::ProbeValue(int Max, bool Increase){
	if(Increase){
		this->Increase(1);
	}

	// TODO(fusion): Some optimizations made the decompilation output for this
	// `RandomFactor` look very weird. It looks correct but we should come back
	// to it.
	int RandomFactor = ((rand() % 100) + (rand() % 100)) / 2;
	int MaxValue = Max * (this->Get() * 5 + 50);
	int Result = (RandomFactor * MaxValue) / 10000;
	return Result;
}

bool TSkillProbe::Probe(int Diff, int Prob, bool Increase){
	if(Increase){
		this->Increase(1);
	}

	// TODO(fusion): Not sure what's going on here.
	bool Result = true;
	if(Diff != 0){
		if(this->Act >= (rand() % Diff)){
			Result = (rand() % 100) <= Prob;
		}else{
			Result = false;
		}
	}
	return Result;
}

bool TSkillProbe::SetTimer(int Cycle, int Count, int MaxCount, int AdditionalValue){
	this->Cycle = Cycle;
	this->Count = Count;
	this->MaxCount = MaxCount;

	if(this->Master == NULL){
		error("TSkillProbe::SetTimer: GetMaster liefert NULL zurueck!\n");
		return false;
	}

	if(this->Master->Type == PLAYER){
		((TPlayer*)this->Master)->CheckState();
		SendPlayerData(this->Master->Connection);
	}

	return true;
}

bool TSkillProbe::Jump(int Range){
	TCreature *Master = this->Master;
	if(Master == NULL){
		error("TSkillProbe::Jump: GetMaster liefert NULL zurueck!\n");
		return false;
	}

	if(Master->Type == PLAYER){
		if(this->SkNr == SKILL_MAGIC_LEVEL){
			SendPlayerData(Master->Connection);
		}else{
			SendPlayerSkills(Master->Connection);
		}

		if(Range > 0){
			switch(this->SkNr){
				case SKILL_MAGIC_LEVEL:{
					SendMessage(Master->Connection, TALK_EVENT_MESSAGE,
							"You advanced to magic level %d.", this->Get());
					break;
				}
				case SKILL_SHIELDING:{
					SendMessage(Master->Connection, TALK_EVENT_MESSAGE, "You advanced in shielding.");
					break;
				}
				case SKILL_DISTANCE:{
					SendMessage(Master->Connection, TALK_EVENT_MESSAGE, "You advanced in distance fighting.");
					break;
				}
				case SKILL_SWORD:{
					SendMessage(Master->Connection, TALK_EVENT_MESSAGE, "You advanced in sword fighting.");
					break;
				}
				case SKILL_CLUB:{
					SendMessage(Master->Connection, TALK_EVENT_MESSAGE, "You advanced in club fighting.");
					break;
				}
				case SKILL_AXE:{
					SendMessage(Master->Connection, TALK_EVENT_MESSAGE, "You advanced in axe fighting.");
					break;
				}
				case SKILL_FIST:{
					SendMessage(Master->Connection, TALK_EVENT_MESSAGE, "You advanced in fist fighting.");
					break;
				}
				case SKILL_FISHING:{
					SendMessage(Master->Connection, TALK_EVENT_MESSAGE, "You advanced in fishing.");
					break;
				}
			}
		}
	}

	return true;
}

void TSkillProbe::Event(int Range){
	if(this->Cycle == 0){
		TCreature *Master = this->Master;
		if(Master == NULL){
			error("TSkillProbe::Event: GetMaster liefert NULL zurueck!\n");
			return;
		}

		this->MDAct = 0;
		if(Master->Type == PLAYER){
			// TODO(fusion): This is weird because `SKILL_GO_STRENGTH` should
			// be TSkillGoStrength, instead of TSkillProbe.
			if(this->SkNr == SKILL_GO_STRENGTH){
				((TPlayer*)Master)->CheckState();
			}

			SendPlayerSkills(Master->Connection);
		}
	}
}

// Creature Functions
//==============================================================================
// TODO(fusion): This was the first function I attempted to cleanup but soon
// realized we should start with the building blocks of the codebase, namely
// TSkill, TSkillBase, etc...
//	We should probably come back to this once we start doing creature functions
// again.
void CheckMana(TCreature *Creature, int ManaPoints, int SoulPoints, int Delay){
	if(Creature == NULL){
		error("CheckMana: Übergebene Kreatur existiert nicht.\n");
		throw ERROR;
	}

	if(Creature->Type != PLAYER || ManaPoints < 0)
		return;

	TSkill *Mana = Creature->Skills[SKILL_MANA];
	if(Mana == NULL){
		error("CheckMana: Kein Skill MANA!\n");
		throw ERROR;
	}

	TSkill *Soul = Creature->Skills[SKILL_SOUL];
	if(Soul == NULL){
		error("CheckMana: Kein Skill SOULPOINTS!\n");
		throw ERROR;
	}

	if(!CheckRight(Creature->ID, UNLIMITED_MANA)){
		if(Mana->Get() < ManaPoints)
			throw NOTENOUGHMANA;

		if(Soul->Get() < SoulPoints)
			throw NOTENOUGHSOULPOINTS;

		Mana->Change(-ManaPoints);
		Soul->Change(-SoulPoints);
	}

	if(ManaPoints > 0){
		Creature->Skills[SKILL_MAGIC_LEVEL]->Increase(ManaPoints);
	}

	// NOTE(fusion): Maintain largest exhaust?
	int EarliestSpellTime = Delay + ServerMilliseconds;
	if(Creature->EarliestSpellTime < EarliestSpellTime)
		Creature->EarliestSpellTime = EarliestSpellTime;
}