randelreiss / nothack

Inverse of the typical RPG
1 stars 0 forks source link

Add Rings #2

Open randelreiss opened 5 years ago

randelreiss commented 5 years ago

Add equipment class: Rings. They are Equiped - not used or applied. Recovered as loot off the dead Adventurers.

randelreiss commented 5 years ago

Below code would work for minimal Ring support. Essentially all of the capabilities of weapon and armour. Attributes could be added later for STR, DEX, INT, health & mana regen, health & mana max. If a speed attribute was added to Character movement, possible the player Guardian or invading Adventurer gets 2 or more moves in a turn with a +2 Ring of Movement, for example. *** Before any of these changes, some basic debugging display to vet Adventurer object instance stats should be done.

entities.py:

EQUIPPABLE = ['weapon', 'armor', 'ring']

class Character(TileSprite):
    def __init__(self, imageFilename, parent, x, y, stats, isPlayer = 0):
            self.equipped = {
            'weapon' : None,
            'armor'    : None,
            'ring'        : None,
            }`

class Ring(Item):
    def __init__(self, imageFilename, parent, x, y, stats):
        Item.__init__(self, imageFilename, parent, x, y, stats)
        self._toHitBonus = float(stats.get('toHit', 0)) / 100.0
        self.damageMin = stats.get('damageMin', 0)
        self.damageMax = stats.get('damageMax', 0)
        self._absorb = stats.get('absorb', 0)
        self._toDodgeBonus = float(stats.get('toDodge', 0)) / 100.0
        self._stats['type'] = 'ring'

    def equip(self, character):
        character.toHit += self._toHitBonus
        character.toDodge += self._toDodgeBonus
        return 1

    def deequip(self, character):
        character.toHit -= self._toHitBonus
        character.toDodge -= self._toDodgeBonus
        return 1

    def getType(self):
        return 'ring'

ai.py:

def createAdventurer(entrances, engine):
    chosen = random.choice(entrances)

    ring = [
        '+%d Ring of Damage', '+%d Ring of Dodging',
        '+%d Ring of Absorption', '+%d Ring of Hitting',
        '+%d Adevnturer\'s Ring', '+%d Nondescript Ring',
        '+%d Ordinary Ring' ]
    ringPlus = int(random.uniform(1, 13))
    ringStats = {
        'name' : random.choice(armor) % ringPlus,
        'damageMin' : 15 + weaponPlus,
        'damageMax' : 65 + weaponPlus,
        'toHit' : weaponPlus,`
        'absorb' : 10 + ringPlus,
        'toDodge' : 10 + rinPlus,
        }
    ring = entities.Ring('ing.png', engine, 0, 0, ringStats)
    adventurer.giveItem(ring)
    adventurer.equip(ring)
    return adventurer