forked from irmen/Tale
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from neph1/update-v0.33.0
Update v0.33.0
- Loading branch information
Showing
14 changed files
with
352 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
|
||
import random | ||
from typing import Optional | ||
from tale import base, util, cmds | ||
from tale import magic | ||
from tale.cmds import cmd | ||
from tale.errors import ActionRefused, ParseError | ||
from tale.magic import MagicType, MagicSkill, Spell | ||
from tale.player import Player | ||
|
||
|
||
@cmd("heal") | ||
def do_heal(player: Player, parsed: base.ParseResult, ctx: util.Context) -> None: | ||
""" Heal someone or something """ | ||
|
||
skillValue = player.stats.magic_skills.get(MagicType.HEAL, None) | ||
if not skillValue: | ||
raise ActionRefused("You don't know how to heal") | ||
spell = magic.spells[MagicType.HEAL] # type: Spell | ||
|
||
num_args = len(parsed.args) | ||
|
||
level = player.stats.level | ||
if num_args == 2: | ||
level = int(parsed.args[1]) | ||
|
||
if not spell.check_cost(player.stats.magic_points, level): | ||
raise ActionRefused("You don't have enough magic points") | ||
|
||
if num_args < 1: | ||
raise ParseError("You need to specify who or what to heal") | ||
try: | ||
entity = str(parsed.args[0]) | ||
except ValueError as x: | ||
raise ActionRefused(str(x)) | ||
|
||
result = player.location.search_living(entity) # type: Optional[base.Living] | ||
if not result or not isinstance(result, base.Living): | ||
raise ActionRefused("Can't heal that") | ||
|
||
|
||
player.stats.magic_points -= spell.base_cost * level | ||
|
||
if random.randint(1, 100) > skillValue: | ||
player.tell("Your healing spell fizzles out", evoke=True, short_len=True) | ||
return | ||
|
||
result.stats.replenish_hp(5 * level) | ||
player.tell("You cast a healing spell that heals %s for %d hit points" % (result.name, 5 * level), evoke=True) | ||
player.tell_others("%s casts a healing spell that heals %s" % (player.name, result.name), evoke=True) | ||
|
||
|
||
@cmd("bolt") | ||
def do_bolt(player: Player, parsed: base.ParseResult, ctx: util.Context) -> None: | ||
""" Cast a bolt of energy """ | ||
|
||
skillValue = player.stats.magic_skills.get(MagicType.BOLT, None) | ||
if not skillValue: | ||
raise ActionRefused("You don't know how to cast a bolt") | ||
|
||
spell = magic.spells[MagicType.BOLT] # type: Spell | ||
|
||
num_args = len(parsed.args) | ||
|
||
level = player.stats.level | ||
if num_args == 2: | ||
level = int(parsed.args[1]) | ||
|
||
if not spell.check_cost(player.stats.magic_points, level): | ||
raise ActionRefused("You don't have enough magic points") | ||
|
||
if num_args < 1: | ||
raise ParseError("You need to specify who or what to attack") | ||
|
||
try: | ||
entity = str(parsed.args[0]) | ||
except ValueError as x: | ||
raise ActionRefused(str(x)) | ||
|
||
result = player.location.search_living(entity) # type: Optional[base.Living] | ||
if not result or not isinstance(result, base.Living): | ||
raise ActionRefused("Can't attack that") | ||
|
||
player.stats.magic_points -= spell.base_cost * level | ||
|
||
if random.randint(1, 100) > skillValue: | ||
player.tell("Your bolt spell fizzles out", evoke=True, short_len=True) | ||
return | ||
|
||
hp = random.randint(1, level) | ||
result.stats.hp -= hp | ||
player.tell("You cast an energy bolt that hits %s for %d damage" % (result.name, hp), evoke=True) | ||
player.tell_others("%s casts an energy bolt that hits %s for %d damage" % (player.name, result.name, hp), evoke=True) | ||
|
||
@cmd("drain") | ||
def do_drain(player: Player, parsed: base.ParseResult, ctx: util.Context) -> None: | ||
""" Drain energy from someone or something """ | ||
|
||
skillValue = player.stats.magic_skills.get(MagicType.DRAIN, None) | ||
if not skillValue: | ||
raise ActionRefused("You don't know how to drain") | ||
|
||
spell = magic.spells[MagicType.DRAIN] # type: Spell | ||
|
||
num_args = len(parsed.args) | ||
|
||
level = player.stats.level | ||
if num_args == 2: | ||
level = int(parsed.args[1]) | ||
|
||
if not spell.check_cost(player.stats.magic_points, level): | ||
raise ActionRefused("You don't have enough magic points") | ||
|
||
if num_args < 1: | ||
raise ParseError("You need to specify who or what to drain") | ||
|
||
try: | ||
entity = str(parsed.args[0]) | ||
except ValueError as x: | ||
raise ActionRefused(str(x)) | ||
|
||
result = player.location.search_living(entity) # type: Optional[base.Living] | ||
if not result or not isinstance(result, base.Living): | ||
raise ActionRefused("Can't drain that") | ||
|
||
player.stats.magic_points -= spell.base_cost * level | ||
|
||
if random.randint(1, 100) > skillValue: | ||
player.tell("Your drain spell fizzles out", evoke=True, short_len=True) | ||
return | ||
|
||
points = random.randint(1, level) | ||
result.stats.combat_points -= points | ||
result.stats.magic_points -= points | ||
|
||
player.stats.magic_points += points | ||
|
||
player.tell("You cast a 'drain' spell that drains %s of %d combat and magic points" % (result.name, points), evoke=True) | ||
player.tell_others("%s casts a 'drain' spell that drains energy from %s" % (player.name, result.name), evoke=True) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from abc import ABC | ||
from enum import Enum | ||
|
||
|
||
class MagicType(Enum): | ||
HEAL = 1 | ||
BOLT = 2 | ||
DRAIN = 3 | ||
REJUVENATE = 4 | ||
|
||
|
||
|
||
class Spell(ABC): | ||
def __init__(self, name: str, base_cost: int, base_value: int = 1, max_level: int = -1): | ||
self.name = name | ||
self.base_value = base_value | ||
self.base_cost = base_cost | ||
self.max_level = max_level | ||
|
||
def check_cost(self, magic_points: int, level: int) -> bool: | ||
return magic_points >= self.base_cost * level | ||
|
||
spells = { | ||
MagicType.HEAL: Spell('heal', base_cost=2, base_value=5), | ||
MagicType.BOLT: Spell('bolt', base_cost=3, base_value=5), | ||
MagicType.DRAIN: Spell('drain', base_cost=3, base_value=5) | ||
} | ||
|
||
class MagicSkill: | ||
def __init__(self, spell: Spell, skill: int = 0): | ||
self.spell = spell | ||
self.skill = skill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.