]> git.localhorst.tv Git - l2e.git/blobdiff - src/common/Capsule.cpp
rough implementation of capsule feeding
[l2e.git] / src / common / Capsule.cpp
index f886724515c3db11f9d5698f3d063f3eb306c45f..487958596fe767b94a75ad20d6e403a04a3f9b4c 100644 (file)
@@ -142,6 +142,35 @@ const Capsule::Class &Capsule::GetClass() const {
 }
 
 
+int Capsule::HungerEmpty() const {
+       return HungerTotal() - HungerFull();
+}
+
+int Capsule::HungerTotal() const {
+       return GetClass().hunger;
+}
+
+int Capsule::HungerFull() const {
+       return GetClass().hungerFull;
+}
+
+bool Capsule::IsHungry() const {
+       return HungerEmpty();
+}
+
+void Capsule::Feed(const common::Item *) {
+       // TODO: find out how to calculate an item's feed value
+       // TODO: an item the capsule favors (changes on every feed and after every
+       //       battle) doubles the value
+       int value = 1;
+       GetClass().hungerFull += value;
+       if (GetClass().hungerFull >= GetClass().hunger) {
+               GetClass().hungerFull = GetClass().hunger;
+               UpgradeClass();
+       }
+}
+
+
 Capsule::Class::Class()
 : name(0)
 , tribe(0)
@@ -150,6 +179,9 @@ Capsule::Class::Class()
 , attackAnimation(0)
 , spellAnimation(0)
 
+, hunger(32)
+, hungerFull(0)
+
 , healthBoost(0) {
        attacks[0] = 0;
        attacks[1] = 0;
@@ -210,6 +242,8 @@ void Capsule::Class::CreateTypeDescription() {
        td.AddField("attackAnimation", FieldDescription(((char *)&c.attackAnimation) - ((char *)&c), Animation::TYPE_ID).SetReferenced());
        td.AddField("spellAnimation", FieldDescription(((char *)&c.spellAnimation) - ((char *)&c), Animation::TYPE_ID).SetReferenced());
 
+       td.AddField("hunger", FieldDescription(((char *)&c.hunger) - ((char *)&c), Interpreter::NUMBER_ID));
+
        td.AddField("healthBoost", FieldDescription(((char *)&c.healthBoost) - ((char *)&c), Interpreter::NUMBER_ID));
        td.AddField("statBoost", FieldDescription(((char *)&c.statBoost) - ((char *)&c), Stats::TYPE_ID));
 }