diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/crcombat.cc | 30 | ||||
| -rw-r--r-- | src/creature.cc | 416 | ||||
| -rw-r--r-- | src/enums.hh | 33 | ||||
| -rw-r--r-- | src/monster.hh | 3 | ||||
| -rw-r--r-- | src/player.hh | 1 | ||||
| -rw-r--r-- | src/stubs.hh | 5 |
6 files changed, 472 insertions, 16 deletions
diff --git a/src/crcombat.cc b/src/crcombat.cc index 7ad7534..2843cd3 100644 --- a/src/crcombat.cc +++ b/src/crcombat.cc @@ -839,10 +839,17 @@ void TCombat::DistanceAttack(TCreature *Target){ ANIMATION_NONE, 2, &Impact, EFFECT_BURST_ARROW); } - if(random(0, 99) < Fragility){ - Delete(this->Ammo, 1); - }else{ - Move(0, this->Ammo, DropCon, 1, false, NONE); + try{ + if(random(0, 99) < Fragility){ + Delete(this->Ammo, 1); + }else{ + Move(0, this->Ammo, DropCon, 1, false, NONE); + } + }catch(RESULT err){ + if(err != DESTROYED){ + error("TCombat::RangeAttack: Konnte Ammo nicht verschieben/löschen" + " (Exception %d, [%d,%d,%d].\n", err, DropX, DropY, DropZ); + } } if(!Hit){ @@ -918,11 +925,12 @@ void TCombat::DistributeExperiencePoints(uint32 Exp){ int MasterLevel = Master->Skills[SKILL_LEVEL]->Get(); int AttackerLevel = Attacker->Skills[SKILL_LEVEL]->Get(); int MaxLevel = (MasterLevel * 11) / 10; - if(AttackerLevel < MaxLevel){ - Amount = ((MaxLevel - AttackerLevel) * Amount) / MasterLevel; - }else{ - Amount = 0; - } + if(AttackerLevel <= MaxLevel){ + continue; + } + + Amount = ((MaxLevel - AttackerLevel) * Amount) / MasterLevel; + print(3, "%s erhält %d EXP.\n", Attacker->Name, Amount); } if(Amount > 0){ @@ -944,8 +952,8 @@ void TCombat::DistributeExperiencePoints(uint32 Exp){ } } - Attacker->Skills[0]->Increase(Amount); - TextualEffect(Attacker->CrObject, 0xD7, "%d", Amount); + Attacker->Skills[SKILL_LEVEL]->Increase(Amount); + TextualEffect(Attacker->CrObject, COLOR_WHITE, "%d", Amount); } } } diff --git a/src/creature.cc b/src/creature.cc index a02cb82..4fee0b3 100644 --- a/src/creature.cc +++ b/src/creature.cc @@ -1,4 +1,5 @@ #include "creature.hh" +#include "monster.hh" #include "enums.hh" #include "stubs.hh" @@ -54,3 +55,418 @@ TCreature::TCreature(void) : void TCreature::Attack(void){ this->Combat.Attack(); } + +// TODO(fusion): This probably belongs elsewhere but we should come back to +// this when we're wrapping up creature files. +static bool IsCreaturePlayer(uint32 CreatureID){ + return CreatureID < 0x40000000; +} + +// TODO(fusion): This probably belongs elsewhere but we should come back to +// this when we're wrapping up creature files. +static void AddKillStatistics(int AttackerRace, int DefenderRace){ + // NOTE(fusion): I think the race name can be "human" only for players, + // which means we're probably tracking how many creatures are killed by + // players with `KilledCreatures`, and how many players are killed by + // creatures with `KilledPlayers`. + + if(strcmp(RaceData[AttackerRace].Name, "human") == 0){ + KilledCreatures[DefenderRace] += 1; + } + + // NOTE(fusion): This seems to track how many players are killed by + if(strcmp(RaceData[DefenderRace].Name, "human") == 0){ + KilledPlayers[AttackerRace] += 1; + } +} + +int TCreature::Damage(TCreature *Attacker, int Damage, int DamageType){ + if(this->IsDead || this->Type == NPC){ + return 0; + } + + if(this->Type == PLAYER){ + if(this->Connection != NULL && Attacker != NULL){ + SendMarkCreature(this->Connection, Attacker->ID, COLOR_BLACK); + } + + if(Attacker != NULL && Attacker->Type == PLAYER + && DamageType != DAMAGE_POISON_PERIODIC + && DamageType != DAMAGE_FIRE_PERIODIC + && DamageType != DAMAGE_ENERGY_PERIODIC){ + Damage = (Damage + 1) / 2; + } + } + + // NOTE(fusion): `Responsible` is either the attacker or its master. It is + // always valid if `Attacker` is not NULL. + TCreature *Responsible = Attacker; + if(Attacker != NULL){ + uint32 MasterID = Attacker->GetMaster(); + if(MasterID != 0){ + Responsible = GetCreature(MasterID); + } + + Attacker->BlockLogout(60, this->Type == PLAYER); + if(Responsible != Attacker){ + Responsible->BlockLogout(60, this->Type == PLAYER); + } + + if(this->Type == PLAYER && Responsible->Type == PLAYER){ + ((TPlayer*)Responsible)->RecordAttack(this->ID); + } + } + + if(this->Type == PLAYER){ + if(CheckRight(this->ID, INVULNERABLE)){ + Damage = 0; + } + + // NOTE(fusion): We're iterating over the victim's inventory to apply + // damage reductions, while the damage is greater than zero. + for(int Position = 1; + Position <= 10 && Damage > 0; + Position += 1){ + Object Obj = GetBodyObject(this->ID, Position); + if(Obj == NONE){ + continue; + } + + ObjectType ObjType = Obj.getObjectType(); + if(ObjType.getFlag(PROTECTION) && ObjType.getFlag(CLOTHES) + && (int)ObjType.getAttribute(BODYPOSITION) == Position + && (ObjType.getAttribute(PROTECTIONDAMAGETYPES) & DamageType) != 0){ + int DamageReduction = ObjType.getAttribute(DAMAGEREDUCTION); + Damage = (Damage * (100 - DamageReduction)) / 100; + if(ObjType.getFlag(WEAROUT)){ + // TODO(fusion): Ugh... The try..catch block might be used only + // when changing the object's type. + try{ + uint32 RemainingUses = Obj.getAttribute(REMAININGUSES); + if(RemainingUses > 1){ + Change(Obj, REMAININGUSES, RemainingUses - 1); + }else{ + ObjectType WearOutType = ObjType.getAttribute(WEAROUTTARGET); + Change(Obj, WearOutType, 0); + } + }catch(RESULT err){ + error("TCreature::Damage: Exception %d beim Abnutzen von Objekt %d.\n", + err, ObjType.TypeID); + } + } + }else if(ObjType.getFlag(PROTECTION) && !ObjType.getFlag(CLOTHES)){ + error("TCreature::Damage: Objekt %d hat PROTECTION, aber nicht CLOTHES.\n", + ObjType.TypeID); + } + } + } + + if(Damage <= 0){ + GraphicalEffect(this->CrObject, EFFECT_POFF); + return 0; + } + + if(DamageType == DAMAGE_POISON_PERIODIC){ + if(RaceData[this->Race].NoPoison){ + return 0; + } + + if(Damage > this->Skills[SKILL_POISON]->TimerValue()){ + this->PoisonDamageOrigin = Attacker->ID; + this->SetTimer(SKILL_POISON, Damage, 3, 3, -1); + } + + this->DamageStimulus(Attacker->ID, Damage, DamageType); + return Damage; + }else if(DamageType == DAMAGE_FIRE_PERIODIC){ + if(RaceData[this->Race].NoBurning){ + return 0; + } + + this->FireDamageOrigin = Attacker->ID; + this->SetTimer(SKILL_BURNING, Damage / 10, 8, 8, -1); + this->DamageStimulus(Attacker->ID, Damage, DamageType); + return Damage; + }else if(DamageType == DAMAGE_ENERGY_PERIODIC){ + if(RaceData[this->Race].NoEnergy){ + return 0; + } + + // TODO(fusion): Shouldn't we use `Damage / 25` here? + this->EnergyDamageOrigin = Attacker->ID; + this->SetTimer(SKILL_ENERGY, Damage / 20, 10, 10, -1); + this->DamageStimulus(Attacker->ID, Damage, DamageType); + return Damage; + } + + if((DamageType == DAMAGE_PHYSICAL && RaceData[this->Race].NoHit) + || (DamageType == DAMAGE_POISON && RaceData[this->Race].NoPoison) + || (DamageType == DAMAGE_FIRE && RaceData[this->Race].NoBurning) + || (DamageType == DAMAGE_ENERGY && RaceData[this->Race].NoEnergy) + || (DamageType == DAMAGE_LIFEDRAIN && RaceData[this->Race].NoLifeDrain)){ + GraphicalEffect(this->CrObject, EFFECT_BLOCK_HIT); + return 0; + } + + if(DamageType == DAMAGE_PHYSICAL){ + Damage -= this->Combat.GetArmorStrength(); + if(Damage <= 0){ + GraphicalEffect(this->CrObject, EFFECT_BLOCK_HIT); + return 0; + } + } + + this->DamageStimulus(Attacker->ID, Damage, DamageType); + + // NOTE(fusion): Remove non-player illusion. Might as well be an inlined + // function. + if(this->Type != PLAYER + && this->Outfit.OutfitID == 0 + && this->Outfit.ObjectType == 0){ + this->SetTimer(SKILL_ILLUSION, 0, 0, 0, -1); + this->Outfit = this->OrgOutfit; + AnnounceChangedCreature(this->ID, 3); // CREATURE_OUTFIT_CHANGED ? + NotifyAllCreatures(this->CrObject, 2, NONE); // CREATURE_APPEAR ? + } + + if(DamageType == DAMAGE_MANADRAIN){ + int ManaPoints = this->Skills[SKILL_MANA]->Get(); + if(Damage > ManaPoints){ + Damage = ManaPoints; + } + + if(Damage > 0){ + this->Skills[SKILL_MANA]->Change(-Damage); + if(this->Type == PLAYER && this->Connection != NULL){ + SendMessage(this->Connection, TALK_STATUS_MESSAGE, + "You lose %d mana.", Damage); + } + GraphicalEffect(this->CrObject, EFFECT_MAGIC_RED); + TextualEffect(this->CrObject, COLOR_BLUE, "%d", Damage); + } + + return Damage; + } + + if(this->Skills[SKILL_MANASHIELD]->TimerValue() > 0 + || this->Skills[SKILL_MANASHIELD]->Get() > 0){ + // NOTE(fusion): We only send these if the attack was fully absorbed, + // else it'd be overwritten by whatever effect and messages we send + // next, when the victim's hitpoints are actually touched. + int ManaPoints = this->Skills[SKILL_MANA]->Get(); + if(Damage <= ManaPoints){ + this->Skills[SKILL_MANA]->Change(-Damage); + GraphicalEffect(this->CrObject, EFFECT_MANA_HIT); + TextualEffect(this->CrObject, COLOR_BLUE, "%d", Damage); + if(this->Type == PLAYER && this->Connection != NULL){ + if(Attacker != NULL){ + SendMessage(this->Connection, TALK_STATUS_MESSAGE, + "You lose %d mana blocking an attack by %s.", + Damage, Attacker->Name); + }else{ + SendMessage(this->Connection, TALK_STATUS_MESSAGE, + "You lose %d mana.", Damage); + } + SendPlayerData(this->Connection); + } + return Damage; + } + + this->Skills[SKILL_MANA]->Set(0); + Damage -= ManaPoints; + } + + int HitPoints = this->Skills[SKILL_HITPOINTS]->Get(); + if(Damage > HitPoints){ + Damage = HitPoints; + } + + this->Skills[SKILL_HITPOINTS]->Change(-Damage); + if(Responsible != NULL){ + ASSERT(Attacker != NULL); + if(Responsible == Attacker){ + this->Combat.AddDamageToCombatList(Attacker->ID, Damage); + }else{ + this->Combat.AddDamageToCombatList(Attacker->ID, Damage / 2); + this->Combat.AddDamageToCombatList(Responsible->ID, Damage / 2); + } + } + + int HitEffect = EFFECT_NONE; + int TextColor = COLOR_BLACK; + int SplashLiquid = LIQUID_NONE; + if(DamageType == DAMAGE_PHYSICAL){ + switch(RaceData[this->Race].Blood){ + case BT_BLOOD:{ + HitEffect = EFFECT_BLOOD_HIT; + TextColor = COLOR_RED; + SplashLiquid = LIQUID_BLOOD; + break; + } + case BT_SLIME:{ + HitEffect = EFFECT_POISON_HIT; + TextColor = COLOR_LIGHTGREEN; + SplashLiquid = LIQUID_SLIME; + break; + } + case BT_BONES:{ + HitEffect = EFFECT_BONE_HIT; + TextColor = COLOR_LIGHTGRAY; + break; + } + case BT_FIRE:{ + HitEffect = EFFECT_FIRE_HIT; + TextColor = COLOR_ORANGE; + break; + } + case BT_ENERGY:{ + HitEffect = EFFECT_ENERGY_HIT; + TextColor = COLOR_LIGHTBLUE; + break; + } + default:{ + error("TCreature::Damage: Ungültiger Bluttyp %d für Rasse %d.\n", + RaceData[this->Race].Blood, this->Race); + break; + } + } + }else if(Damage == DAMAGE_POISON){ + HitEffect = EFFECT_POISON; + TextColor = COLOR_LIGHTGREEN; + }else if(DamageType == DAMAGE_FIRE){ + HitEffect = EFFECT_FIRE_HIT; + TextColor = COLOR_ORANGE; + }else if(DamageType == DAMAGE_ENERGY){ + HitEffect = EFFECT_ENERGY_HIT; + TextColor = COLOR_LIGHTBLUE; + }else if(DamageType == DAMAGE_LIFEDRAIN){ + HitEffect = EFFECT_MAGIC_RED; + TextColor = COLOR_RED; + }else{ + // TODO(fusion): The original decompiled function would return here but + // I don't think it's a good idea because it would skip death handling. + error("TCreature::Damage: Ungültiger Schadenstyp %d.\n", DamageType); + //return Damage; + } + + if(HitEffect != EFFECT_NONE){ + GraphicalEffect(this->CrObject, HitEffect); + TextualEffect(this->CrObject, TextColor, "%d", Damage); + if(SplashLiquid != LIQUID_NONE){ + CreatePool(GetMapContainer(this->CrObject), + GetSpecialObject(BLOOD_SPLASH), + SplashLiquid); + } + } + + if(this->Type == PLAYER && this->Connection != NULL){ + if(Attacker != NULL){ + SendMessage(this->Connection, TALK_STATUS_MESSAGE, + "You lose %d hitpoint%s due to an attack by %s.", + Damage, (Damage == 1 ? "" : "s"), Attacker->Name); + }else{ + SendMessage(this->Connection, TALK_STATUS_MESSAGE, + "You lose %d hitpoint%s.", + Damage, (Damage == 1 ? "" : "s")); + } + SendPlayerData(this->Connection); + } + + if(Damage == HitPoints){ + if(this->Type == PLAYER){ + for(int Position = 1; Position <= 10; Position += 1){ + Object Obj = GetBodyObject(this->ID, Position); + if(Obj == NONE){ + continue; + } + + ObjectType ObjType = Obj.getObjectType(); + if(ObjType.getFlag(CLOTHES) && (int)ObjType.getAttribute(BODYPOSITION) == Position){ + ObjectType AmuletOfLossType = GetNewObjectType(77, 12); + if(ObjType == AmuletOfLossType){ + Log("game", "%s stirbt mit Amulett of Loss.\n", this->Name); + this->LoseInventory = 0; + Delete(Obj, -1); + // TODO(fusion): Shouldn't we break here? We could also + // just check if there is an amulet of loss in the necklace + // container instead of iterating over all of them. + } + } + } + } + + int OldLevel = this->Skills[SKILL_LEVEL]->Get(); + this->Death(); + if(Attacker != NULL && this->Type == PLAYER){ + Attacker->BlockLogout(900, true); + if(Responsible != Attacker){ + Responsible->BlockLogout(900, true); + } + } + + uint32 MurdererID = 0; + char Remark[30] = {}; + if(Attacker == NULL){ + AddKillStatistics(0, this->Race); + if(DamageType == DAMAGE_PHYSICAL){ + strcpy(Remark, "a hit"); + }else if(DamageType == DAMAGE_POISON){ + strcpy(Remark, "poison"); + }else if(DamageType == DAMAGE_FIRE){ + strcpy(Remark, "fire"); + }else if(DamageType == DAMAGE_ENERGY){ + strcpy(Remark, "energy"); + }else{ + // NOTE(fusion): We probably don't expect any other damage type + // as the cause of death when there is no attacker. + error("TCreature::Damage: Ungültiger Schadenstyp %d als Todesursache.\n", DamageType); + } + }else{ + AddKillStatistics(Attacker->Race, this->Race); + strcpy(this->Murderer, Attacker->Name); + + if(Responsible->Type == PLAYER){ + MurdererID = Responsible->ID; + } + + if(Attacker->Type != PLAYER){ + strcpy(Remark, Attacker->Name); + } + } + + if(this->Type == PLAYER){ + if(MurdererID != 0 && MurdererID != this->ID){ + bool Justified = true; + if(IsCreaturePlayer(MurdererID)){ + TPlayer *Murderer = GetPlayer(MurdererID); + if(Murderer != NULL){ + Justified = Murderer->IsAttackJustified(this->ID); + Murderer->RecordMurder(this->ID); + } + } + CharacterDeathOrder(this, OldLevel, MurdererID, Remark, !Justified); + } + + uint32 MostDangerousID = this->Combat.GetMostDangerousAttacker(); + if(MostDangerousID != 0 + && MostDangerousID != MurdererID + && MostDangerousID != this->ID + && IsCreaturePlayer(MostDangerousID)){ + bool Justified = true; + TPlayer *MostDangerous = GetPlayer(MostDangerousID); + if(MostDangerous != NULL){ + Justified = MostDangerous->IsAttackJustified(this->ID); + MostDangerous->RecordMurder(this->ID); + } + + // TODO(fusion): The original function is confusing at this point + // but it seems correct that the remark is included only with the + // murderer. + CharacterDeathOrder(this, OldLevel, MostDangerousID, "", !Justified); + } + } + } + + AnnounceChangedCreature(this->ID, 1); // CREATURE_HITPOINTS_CHANGED ? + return Damage; +} diff --git a/src/enums.hh b/src/enums.hh index 4081dce..6d02208 100644 --- a/src/enums.hh +++ b/src/enums.hh @@ -45,10 +45,16 @@ enum ChaseMode: uint8 { CHASE_MODE_RANGE = 2, }; -enum CreatureType: int { - PLAYER = 0, - MONSTER = 1, - NPC = 2, +// NOTE(fusion): Not in debug symbols. +enum Color: int { + COLOR_BLACK = 0, + COLOR_BLUE = 5, + COLOR_LIGHTGREEN = 30, + COLOR_LIGHTBLUE = 35, + COLOR_LIGHTGRAY = 129, + COLOR_RED = 180, + COLOR_ORANGE = 198, + COLOR_WHITE = 215, }; enum CONNECTIONSTATE: int { @@ -62,6 +68,12 @@ enum CONNECTIONSTATE: int { CONNECTION_DISCONNECTED = 7, }; +enum CreatureType: int { + PLAYER = 0, + MONSTER = 1, + NPC = 2, +}; + // NOTE(fusion): Not in debug symbols. enum DamageType: int { DAMAGE_NONE = 0x0000, @@ -77,9 +89,20 @@ enum DamageType: int { DAMAGE_MANADRAIN = 0x0200, }; +// TODO(fusion): Review these names. enum EffectType: int { + EFFECT_NONE = 0, + EFFECT_BLOOD_HIT = 1, + EFFECT_MANA_HIT = 2, EFFECT_POFF = 3, - EFFECT_BURST_ARROW = 7, // Review + EFFECT_BLOCK_HIT = 4, + EFFECT_BURST_ARROW = 7, + EFFECT_POISON = 9, + EFFECT_BONE_HIT = 10, + EFFECT_ENERGY_HIT = 12, + EFFECT_MAGIC_RED = 14, + EFFECT_FIRE_HIT = 16, + EFFECT_POISON_HIT = 17, }; enum FLAG: int { diff --git a/src/monster.hh b/src/monster.hh index dd246a1..f7ce3f5 100644 --- a/src/monster.hh +++ b/src/monster.hh @@ -85,6 +85,9 @@ struct TMonster: TNonplayer { }; #endif +//#define MAX_RACES 512 extern TRaceData RaceData[512]; +extern int KilledCreatures[512]; +extern int KilledPlayers[512]; #endif //TIBIA_MONSTER_HH_ diff --git a/src/player.hh b/src/player.hh index 33ca7c3..b98882e 100644 --- a/src/player.hh +++ b/src/player.hh @@ -77,6 +77,7 @@ struct TPlayer: TCreature { bool IsAttackJustified(uint32 Victim); void RecordAttack(uint32 Victim); + void RecordMurder(uint32 Victim); void CheckState(void); diff --git a/src/stubs.hh b/src/stubs.hh index d3cfcd0..8553177 100644 --- a/src/stubs.hh +++ b/src/stubs.hh @@ -19,17 +19,21 @@ extern void AbortWriter(void); extern void AnnounceChangedCreature(uint32 CreatureID, int Type); extern void BroadcastMessage(int Mode, const char *Text, ...) ATTR_PRINTF(2, 3); extern void Change(Object Obj, ObjectType NewType, uint32 Value); +extern void CharacterDeathOrder(TCreature *Creature, int OldLevel, + uint32 Offender, const char *Remark, bool Unjustified); extern bool CheckRight(uint32 CreatureID, RIGHT Right); extern void CircleShapeSpell(TCreature *Actor, int DestX, int DestY, int DestZ, int Range, int Animation, int Radius, TImpact *Impact, int Effect); extern void CleanHouseField(int x, int y, int z); extern int ComputeDamage(TCreature *Creature, int SpellNr, int Damage, int Variation); extern void CreatePlayerList(bool Online); +extern void CreatePool(Object Con, ObjectType Type, uint32 Value); extern void Delete(Object Obj, int Count); extern Object GetBodyObject(uint32 CreatureID, int Position); extern TCreature *GetCreature(uint32 CreatureID); extern TConnection *GetFirstConnection(void); extern TConnection *GetNextConnection(void); +extern TPlayer *GetPlayer(uint32 CreatureID); extern int GetRacePoison(int Race); extern void GraphicalEffect(int x, int y, int z, int Type); extern void GraphicalEffect(Object Obj, int Type); @@ -61,6 +65,7 @@ extern void SendAll(void); extern void SendAmbiente(TConnection *Connection); extern void SendClearTarget(TConnection *Connection); extern void SendMails(TPlayerData *PlayerData); +extern void SendMarkCreature(TConnection *Connection, uint32 CreatureID, int Color); extern void SendMessage(TConnection *Connection, int Mode, const char *Text, ...) ATTR_PRINTF(3, 4); extern void SendPlayerData(TConnection *Connection); extern void SendPlayerSkills(TConnection *Connection); |
