Skip to content

Commit f48995c

Browse files
authored
Merge pull request #89 from neph1/update-v0.33.0
Update v0.33.0
2 parents 6c8a354 + 58445de commit f48995c

File tree

14 files changed

+352
-15
lines changed

14 files changed

+352
-15
lines changed

llm_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CHARACTER_TEMPLATE: '{"name":"", "description": "50 words", "appearance": "25 wo
1717
FOLLOW_TEMPLATE: '{{"response":"yes or no", "reason":"50 words"}}'
1818
ITEM_TYPES: ["Weapon", "Wearable", "Health", "Money", "Trash", "Food", "Drink", "Key"]
1919
PRE_PROMPT: 'You are a creative game keeper for a role playing game (RPG). You craft detailed worlds and interesting characters with unique and deep personalities for the player to interact with. Do not acknowledge the task or speak directly to the user, just perform it.'
20-
BASE_PROMPT: '<context>{context}</context>\n[USER_START]Rewrite [{input_text}] in your own words using the information found inside the <context> tags to create a background for your text. Use about {max_words} words.'
20+
BASE_PROMPT: '<context>{context}</context>\n[USER_START] Rewrite [{input_text}] in your own words. The information inside the <context> tags should be used to ensure it fits the story. Use about {max_words} words.'
2121
DIALOGUE_PROMPT: '<context>{context}</context>\nThe following is a conversation between {character1} and {character2}; {character2}s sentiment towards {character1}: {sentiment}. Write a single response as {character2} in third person pov, using {character2} description and other information found inside the <context> tags. If {character2} has a quest active, they will discuss it based on its status. Respond in JSON using this template: """{dialogue_template}""". [USER_START]Continue the following conversation as {character2}: {previous_conversation}'
2222
COMBAT_PROMPT: '<context>{context}</context>\nThe following is a combat scene between {attackers} and {defenders} in {location}. [USER_START] Describe the following combat result in about 150 words in vivid language, using the characters weapons and their health status: 1.0 is highest, 0.0 is lowest. Combat Result: {input_text}'
2323
PRE_JSON_PROMPT: 'Below is an instruction that describes a task, paired with an input that provides further context. Write a response in valid JSON format that appropriately completes the request.'

stories/anything/story.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from tale import parse_utils
99
from tale.driver import Driver
1010
from tale.json_story import JsonStory
11+
from tale.magic import MagicType
1112
from tale.main import run_from_cmdline
1213
from tale.player import Player, PlayerConnection
1314
from tale.charbuilder import PlayerNaming
@@ -33,6 +34,10 @@ def init_player(self, player: Player) -> None:
3334
player.stats.set_weapon_skill(weapon_type=WeaponType.ONE_HANDED, value=random.randint(10, 30))
3435
player.stats.set_weapon_skill(weapon_type=WeaponType.TWO_HANDED, value=random.randint(10, 30))
3536
player.stats.set_weapon_skill(weapon_type=WeaponType.UNARMED, value=random.randint(20, 30))
37+
player.stats.magic_skills[MagicType.HEAL] = 30
38+
player.stats.magic_skills[MagicType.BOLT] = 30
39+
player.stats.magic_skills[MagicType.DRAIN] = 30
40+
player.stats.magic_skills[MagicType.REJUVENATE] = 30
3641
pass
3742

3843
def create_account_dialog(self, playerconnection: PlayerConnection, playernaming: PlayerNaming) -> Generator:

stories/dungeon/story.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from tale.dungeon.dungeon_generator import ItemPopulator, Layout, LayoutGenerator, MobPopulator
1212
from tale.items.basic import Money
1313
from tale.json_story import JsonStory
14+
from tale.magic import MagicType
1415
from tale.main import run_from_cmdline
1516
from tale.npc_defs import RoamingMob
1617
from tale.player import Player, PlayerConnection
@@ -44,6 +45,10 @@ def init_player(self, player: Player) -> None:
4445
player.stats.set_weapon_skill(weapon_type=WeaponType.ONE_HANDED, value=random.randint(10, 30))
4546
player.stats.set_weapon_skill(weapon_type=WeaponType.TWO_HANDED, value=random.randint(10, 30))
4647
player.stats.set_weapon_skill(weapon_type=WeaponType.UNARMED, value=random.randint(20, 30))
48+
player.stats.magic_skills[MagicType.HEAL] = 30
49+
player.stats.magic_skills[MagicType.BOLT] = 30
50+
player.stats.magic_skills[MagicType.DRAIN] = 30
51+
player.stats.magic_skills[MagicType.REJUVENATE] = 30
4752
pass
4853

4954
def create_account_dialog(self, playerconnection: PlayerConnection, playernaming: PlayerNaming) -> Generator:

stories/prancingllama/story.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
import tale
66
from tale.base import Location
7+
from tale.cmds import spells
78
from tale.driver import Driver
89
from tale.llm.llm_ext import DynamicStory
10+
from tale.magic import MagicType
911
from tale.main import run_from_cmdline
1012
from tale.player import Player, PlayerConnection
1113
from tale.charbuilder import PlayerNaming
@@ -55,6 +57,7 @@ def init_player(self, player: Player) -> None:
5557
player.stats.set_weapon_skill(weapon_type=WeaponType.ONE_HANDED, value=25)
5658
player.stats.set_weapon_skill(weapon_type=WeaponType.TWO_HANDED, value=15)
5759
player.stats.set_weapon_skill(weapon_type=WeaponType.UNARMED, value=35)
60+
player.stats.magic_skills[MagicType.HEAL] = 50
5861

5962
def create_account_dialog(self, playerconnection: PlayerConnection, playernaming: PlayerNaming) -> Generator:
6063
"""

stories/prancingllama/zones/prancingllama.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import random
22

3-
from tale.base import Location, Item, Exit, Door, Key, Living, ParseResult, Weapon
3+
from tale.base import Location, Item, Exit, Weapon
44
from tale.errors import StoryCompleted
55
from tale.items.basic import Note
6-
from tale.lang import capital
7-
from tale.player import Player
86
from tale.util import Context, call_periodically
97
from tale.verbdefs import AGGRESSIVE_VERBS
108
from tale.verbdefs import VERBS

tale/accounts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ def _create_database(self) -> None:
110110
strength integer NOT NULL,
111111
dexterity integer NOT NULL,
112112
weapon_skills varchar NOT NULL,
113+
magic_skills varchar NOT NULL,
113114
combat_points integer NOT NULL,
114115
max_combat_points integer NOT NULL,
116+
magic_points integer NOT NULL,
117+
max_magic_points integer NOT NULL,
115118
FOREIGN KEY(account) REFERENCES Account(id)
116119
);
117120
""")

tale/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
from tale.coord import Coord
5252
from tale.llm.contexts.CombatContext import CombatContext
53+
from tale.magic import MagicSkill, MagicType
5354

5455
from . import lang
5556
from . import mud_context
@@ -975,8 +976,11 @@ def __init__(self) -> None:
975976
self.dexterity = 3
976977
self.unarmed_attack = Weapon(UnarmedAttack.FISTS.name, weapon_type=WeaponType.UNARMED)
977978
self.weapon_skills = {} # type: Dict[WeaponType, int] # weapon type -> skill level
979+
self.magic_skills = {} # type: Dict[MagicType, MagicSkill]
978980
self.combat_points = 0 # combat points
979981
self.max_combat_points = 5 # max combat points
982+
self.max_magic_points = 5 # max magic points
983+
self.magic_points = 0 # magic points
980984

981985
def __repr__(self):
982986
return "<Stats: %s>" % self.__dict__
@@ -1025,6 +1029,14 @@ def replenish_combat_points(self, amount: int = None) -> None:
10251029
if self.combat_points > self.max_combat_points:
10261030
self.combat_points = self.max_combat_points
10271031

1032+
def replenish_magic_points(self, amount: int = None) -> None:
1033+
if amount:
1034+
self.magic_points += amount
1035+
else:
1036+
self.magic_points = self.max_magic_points
1037+
if self.magic_points > self.max_magic_points:
1038+
self.magic_points = self.max_magic_points
1039+
10281040
class Living(MudObject):
10291041
"""
10301042
A living entity in the mud world (also known as an NPC).

tale/cmds/spells.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
2+
import random
3+
from typing import Optional
4+
from tale import base, util, cmds
5+
from tale import magic
6+
from tale.cmds import cmd
7+
from tale.errors import ActionRefused, ParseError
8+
from tale.magic import MagicType, MagicSkill, Spell
9+
from tale.player import Player
10+
11+
12+
@cmd("heal")
13+
def do_heal(player: Player, parsed: base.ParseResult, ctx: util.Context) -> None:
14+
""" Heal someone or something """
15+
16+
skillValue = player.stats.magic_skills.get(MagicType.HEAL, None)
17+
if not skillValue:
18+
raise ActionRefused("You don't know how to heal")
19+
spell = magic.spells[MagicType.HEAL] # type: Spell
20+
21+
num_args = len(parsed.args)
22+
23+
level = player.stats.level
24+
if num_args == 2:
25+
level = int(parsed.args[1])
26+
27+
if not spell.check_cost(player.stats.magic_points, level):
28+
raise ActionRefused("You don't have enough magic points")
29+
30+
if num_args < 1:
31+
raise ParseError("You need to specify who or what to heal")
32+
try:
33+
entity = str(parsed.args[0])
34+
except ValueError as x:
35+
raise ActionRefused(str(x))
36+
37+
result = player.location.search_living(entity) # type: Optional[base.Living]
38+
if not result or not isinstance(result, base.Living):
39+
raise ActionRefused("Can't heal that")
40+
41+
42+
player.stats.magic_points -= spell.base_cost * level
43+
44+
if random.randint(1, 100) > skillValue:
45+
player.tell("Your healing spell fizzles out", evoke=True, short_len=True)
46+
return
47+
48+
result.stats.replenish_hp(5 * level)
49+
player.tell("You cast a healing spell that heals %s for %d hit points" % (result.name, 5 * level), evoke=True)
50+
player.tell_others("%s casts a healing spell that heals %s" % (player.name, result.name), evoke=True)
51+
52+
53+
@cmd("bolt")
54+
def do_bolt(player: Player, parsed: base.ParseResult, ctx: util.Context) -> None:
55+
""" Cast a bolt of energy """
56+
57+
skillValue = player.stats.magic_skills.get(MagicType.BOLT, None)
58+
if not skillValue:
59+
raise ActionRefused("You don't know how to cast a bolt")
60+
61+
spell = magic.spells[MagicType.BOLT] # type: Spell
62+
63+
num_args = len(parsed.args)
64+
65+
level = player.stats.level
66+
if num_args == 2:
67+
level = int(parsed.args[1])
68+
69+
if not spell.check_cost(player.stats.magic_points, level):
70+
raise ActionRefused("You don't have enough magic points")
71+
72+
if num_args < 1:
73+
raise ParseError("You need to specify who or what to attack")
74+
75+
try:
76+
entity = str(parsed.args[0])
77+
except ValueError as x:
78+
raise ActionRefused(str(x))
79+
80+
result = player.location.search_living(entity) # type: Optional[base.Living]
81+
if not result or not isinstance(result, base.Living):
82+
raise ActionRefused("Can't attack that")
83+
84+
player.stats.magic_points -= spell.base_cost * level
85+
86+
if random.randint(1, 100) > skillValue:
87+
player.tell("Your bolt spell fizzles out", evoke=True, short_len=True)
88+
return
89+
90+
hp = random.randint(1, level)
91+
result.stats.hp -= hp
92+
player.tell("You cast an energy bolt that hits %s for %d damage" % (result.name, hp), evoke=True)
93+
player.tell_others("%s casts an energy bolt that hits %s for %d damage" % (player.name, result.name, hp), evoke=True)
94+
95+
@cmd("drain")
96+
def do_drain(player: Player, parsed: base.ParseResult, ctx: util.Context) -> None:
97+
""" Drain energy from someone or something """
98+
99+
skillValue = player.stats.magic_skills.get(MagicType.DRAIN, None)
100+
if not skillValue:
101+
raise ActionRefused("You don't know how to drain")
102+
103+
spell = magic.spells[MagicType.DRAIN] # type: Spell
104+
105+
num_args = len(parsed.args)
106+
107+
level = player.stats.level
108+
if num_args == 2:
109+
level = int(parsed.args[1])
110+
111+
if not spell.check_cost(player.stats.magic_points, level):
112+
raise ActionRefused("You don't have enough magic points")
113+
114+
if num_args < 1:
115+
raise ParseError("You need to specify who or what to drain")
116+
117+
try:
118+
entity = str(parsed.args[0])
119+
except ValueError as x:
120+
raise ActionRefused(str(x))
121+
122+
result = player.location.search_living(entity) # type: Optional[base.Living]
123+
if not result or not isinstance(result, base.Living):
124+
raise ActionRefused("Can't drain that")
125+
126+
player.stats.magic_points -= spell.base_cost * level
127+
128+
if random.randint(1, 100) > skillValue:
129+
player.tell("Your drain spell fizzles out", evoke=True, short_len=True)
130+
return
131+
132+
points = random.randint(1, level)
133+
result.stats.combat_points -= points
134+
result.stats.magic_points -= points
135+
136+
player.stats.magic_points += points
137+
138+
player.tell("You cast a 'drain' spell that drains %s of %d combat and magic points" % (result.name, points), evoke=True)
139+
player.tell_others("%s casts a 'drain' spell that drains energy from %s" % (player.name, result.name), evoke=True)
140+
141+

tale/driver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,9 @@ def build_location(self, targetLocation: base.Location, zone: Zone, player: play
961961
def do_on_player_death(self, player: player.Player) -> None:
962962
pass
963963

964-
@util.call_periodically(10)
964+
@util.call_periodically(20)
965965
def replenish(self):
966966
for player in self.all_players.values():
967967
player.player.stats.replenish_hp(1)
968-
player.player.stats.replenish_combat_points(1)
968+
player.player.stats.replenish_combat_points(1)
969+
player.player.stats.replenish_magic_points(1)

tale/items/basic.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def init(self) -> None:
220220
def consume(self, actor: 'Living'):
221221
if self not in actor.inventory:
222222
raise ActionRefused("You don't have that.")
223-
actor.stats.hp += self.affect_thirst
224223
actor.tell("You drink the %s." % (self.title), evoke=True, short_len=True)
225224
actor.tell_others("{Actor} drinks the %s." % (self.title))
226225
self.destroy(util.Context.from_global())
@@ -243,7 +242,6 @@ def init(self) -> None:
243242
def consume(self, actor: 'Living'):
244243
if self not in actor.inventory:
245244
raise ActionRefused("You don't have that.")
246-
actor.stats.hp += self.affect_fullness
247245
actor.tell("You eat the %s." % (self.title), evoke=True, short_len=True)
248246
actor.tell_others("{Actor} eats the %s." % (self.title))
249247
self.destroy(util.Context.from_global())

0 commit comments

Comments
 (0)