forked from madcowfred/evething
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskill.py
More file actions
129 lines (104 loc) · 5.08 KB
/
Copy pathskill.py
File metadata and controls
129 lines (104 loc) · 5.08 KB
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
# ------------------------------------------------------------------------------
# Copyright (c) 2010-2013, EVEthing team
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
import cPickle
import math
from django.db import models
from thing.models.item import Item
# ------------------------------------------------------------------------------
try:
SKILL_MAP = cPickle.load(open('skill_map.pickle', 'r'))
except:
SKILL_MAP = {}
# ------------------------------------------------------------------------------
class Skill(models.Model):
CHARISMA_ATTRIBUTE = 164
INTELLIGENCE_ATTRIBUTE = 165
MEMORY_ATTRIBUTE = 166
PERCEPTION_ATTRIBUTE = 167
WILLPOWER_ATTRIBUTE = 168
ATTRIBUTE_CHOICES = (
(CHARISMA_ATTRIBUTE, 'Cha'),
(INTELLIGENCE_ATTRIBUTE, 'Int'),
(MEMORY_ATTRIBUTE, 'Mem'),
(PERCEPTION_ATTRIBUTE, 'Per'),
(WILLPOWER_ATTRIBUTE, 'Wil'),
)
ATTRIBUTE_MAP = {
CHARISMA_ATTRIBUTE: ('cha_attribute', 'cha_bonus'),
INTELLIGENCE_ATTRIBUTE: ('int_attribute', 'int_bonus'),
MEMORY_ATTRIBUTE: ('mem_attribute', 'mem_bonus'),
PERCEPTION_ATTRIBUTE: ('per_attribute', 'per_bonus'),
WILLPOWER_ATTRIBUTE: ('wil_attribute', 'wil_bonus'),
}
item = models.OneToOneField(Item, primary_key=True)
rank = models.SmallIntegerField()
description = models.TextField()
primary_attribute = models.SmallIntegerField(choices=ATTRIBUTE_CHOICES)
secondary_attribute = models.SmallIntegerField(choices=ATTRIBUTE_CHOICES)
class Meta:
app_label = 'thing'
def __unicode__(self):
return '%s (Rank %d; %s/%s)' % (self.item.name, self.rank, self.get_primary_attribute_display(),
self.get_secondary_attribute_display())
def __html__(self):
return "<strong>Primary:</strong> %s / <strong>Secondary</strong>: %s<br><br>%s" % (
self.get_primary_attribute_display(),
self.get_secondary_attribute_display(),
self.description.replace('\n', '<br>'),
)
def get_sp_at_level(self, level=5):
if level == 0:
return 0
else:
return int(math.ceil(2 ** ((2.5 * level) - 2.5) * 250 * self.rank))
def get_sp_per_minute(self, character, force_bonus=None):
pri_attrs = Skill.ATTRIBUTE_MAP[self.primary_attribute]
sec_attrs = Skill.ATTRIBUTE_MAP[self.secondary_attribute]
if force_bonus is None:
pri = getattr(character.details, pri_attrs[0]) + getattr(character.details, pri_attrs[1])
sec = getattr(character.details, sec_attrs[0]) + getattr(character.details, sec_attrs[1])
else:
pri = getattr(character.details, pri_attrs[0]) + force_bonus
sec = getattr(character.details, sec_attrs[0]) + force_bonus
return pri + (sec / 2.0)
def get_sppm_stats(self, stats, implants):
pri_attrs = Skill.ATTRIBUTE_MAP[self.primary_attribute]
sec_attrs = Skill.ATTRIBUTE_MAP[self.secondary_attribute]
pri = stats.get(pri_attrs[0]) + implants.get(pri_attrs[1])
sec = stats.get(sec_attrs[0]) + implants.get(sec_attrs[1])
return pri + (sec / 2.0)
# ------------------------------------------------------------------------------
@staticmethod
def get_prereqs(skill_id):
'Get all pre-requisite skills for a given skill ID'
def _recurse_prereqs(prereqs, skill):
for sid, level in SKILL_MAP.get(skill, {}).values():
prereqs.append([sid, level])
_recurse_prereqs(prereqs, sid)
prereqs = []
_recurse_prereqs(prereqs, skill_id)
# Return a reversed list so it's in training order
return list(reversed(prereqs))
# ------------------------------------------------------------------------------