-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.py
156 lines (133 loc) · 4.93 KB
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from critters import Critter, ActionCost
import gl
import util
from inventory import Inventory, categorize_items
search_skill_scale = [x for x in xrange(5, 1000, 17)]
search_skill_scale.insert(0, 0)
search_skill_base_chance = 10
class PassiveSkill(object):
pass
class SearchSkill(PassiveSkill):
def __init__(self, player):
self.skill = 1
self.player = player
def observe(self, tile):
if self.skill >= tile.skill:
total_chance = min(search_skill_base_chance + (self.skill - tile.skill), 25) #cap at 25%
#if player search level is higher than feature's then we have tile_skill/skill chance of feature veing revealed
if util.chance_in(total_chance, 100):
tile.found(self.player)
else: #player skill is lover
total_chance = int(max(1, search_skill_base_chance - ((tile.skill - self.skill) * 1.5)))
if util.chance_in(total_chance, 100):
tile.found(self.player)
class PlayerActionCost(ActionCost):
search = ActionCost.move
def __init__(self, **args):
super(PlayerActionCost, self).__init__(**args)
self.move = 5.0
class Player(Critter):
pronoun = 'you'
x, y = 0, 0
char = '@'
color = (255, 255, 255)
skip_register = True
fov_range = 10
base_hp = 155
base_mp = 10
mp = 10
hitpoints = base_hp
name = 'you'
xl = 1
xp = 0
energy = 10.0
current_energy = energy
action_cost = PlayerActionCost()
time = 'past' #present or future
def __init__(self):
self.map = None
self.gold = 0
self.search_skill = SearchSkill(self)
self.inventory = Inventory(self)
def move(self, dx, dy):
newx, newy = self.x + dx, self.y + dy
if not self.map.coords_okay(newx, newy):
return False, False, None
if self.map.has_critter_at((newx, newy)):
cost = self.attack(self.map.get_critter_at(newx, newy))
return True, False, cost
next_tile = self.map.tile_at(newx, newy)
move_to, take_turn, fov_recalc = next_tile.player_move_into(self, newx, newy, self.map)
if move_to:
#todo move cost should be changed by the type of tile we're entering
self.x, self.y = newx, newy
self.search(self.map, 4)
return take_turn, fov_recalc, self.action_cost.move
elif next_tile.is_wall():
gl.message("You bump into wall")
return take_turn, fov_recalc, None
def search(self, map, range=None):
if not range:
range = self.fov_range
map.iterate_fov(self.x, self.y, range, self.see)
return self.action_cost.search
def descend(self, map):
if map.descend_or_ascend(True):
return self.action_cost.stairsdown / 2
return None
def ascend(self, map):
if map.descend_or_ascend(False):
return self.action_cost.stairsdown / 2
return None
def die(self, killer):
gl.message( 'You die...', 'CRITICAL')
gl.__game_state__ = "died"
def earn_exp(self, src):
self.xp += src.xp
if self.xp > util.xp_for_lvl(self.xl):
self.lvl_up()
def lvl_up(self):
self.xl += 1
gl.message ("Congratulations! Level up", 'INFO')
def see(self, tile, tilex, tiley, map):
if tile.items and len(tile.items):
item = tile.items[0]
if not getattr(item, 'seen', False):
gl.message('You see %s' % item)
item.seen = True
if getattr(tile, 'has_hidden', False):
self.search_skill.observe(tile)
def take_damage(self, mob, dmgs, attack):
#take evasion into account
super(Player, self).take_damage(mob, dmgs, attack)
if self.hitpoints <= self.base_hp * gl.__hp_warning__:
gl.message('Low HP!!!', 'WARN')
def gethp(self):
return self.hitpoints
def sethp(self, value):
self.hitpoints = value
gl.require_hud_update()
hp = property(gethp, sethp)
def get_inventory_categorized(self):
""" get_inventory_categorized() => {category :[items]}
Returns list of items divided by category
"""
return self.inventory.categorized_view()
def _item_pickup(self, item):
self.inventory.add_item(item)
gl.message('You pick up ' + str(item))
item.on_pickup(self)
def pickup(self, map, multi_select_handler=None):
tile = self.map.tile_at(self.x, self.y)
items = tile.items
if not items:
gl.message('There is nothing to pick up here')
if len(items) == 1:
item = items.pop()
self._item_pickup(item)
elif multi_select_handler:
selected_items = multi_select_handler(categorize_items(items))
if selected_items:
for item in selected_items:
items.remove(item)
self._item_pickup(item)