forked from Cryz/battle_royale_sim
item
This commit is contained in:
21
entities/items/item.py
Normal file
21
entities/items/item.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import random as _random
|
||||
|
||||
class BrSimItem():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def get_name(self):
|
||||
return self.name
|
||||
|
||||
def get_item_type(self):
|
||||
return self.item_type
|
||||
|
||||
def get_weight(self):
|
||||
return self.weight
|
||||
|
||||
def is_weapon(self):
|
||||
return False
|
||||
|
||||
def is_cure(self):
|
||||
return False
|
||||
24
entities/items/weapon_syms.py
Normal file
24
entities/items/weapon_syms.py
Normal file
@@ -0,0 +1,24 @@
|
||||
KNIFE= 1
|
||||
ARCH= 2
|
||||
|
||||
SHORT_RANGE= 1
|
||||
FAR_RANGE= 2
|
||||
|
||||
WEAPONS= {
|
||||
KNIFE: {
|
||||
'weight': 1,
|
||||
'name': 'knife',
|
||||
'damage': 3,
|
||||
'miss_chance': 0, # from 0 to 100, this is the probably to miss the hit
|
||||
'ammons': -1, # -1, no limit
|
||||
'range': SHORT_RANGE,
|
||||
},
|
||||
ARCH: {
|
||||
'weight': 2,
|
||||
'name': 'gun',
|
||||
'damage': 3,
|
||||
'miss_chance': 20, # from 0 to 100, this is the probably to miss the hit
|
||||
'ammons': 10, # -1, no limit
|
||||
'range': FAR_RANGE,
|
||||
},
|
||||
}
|
||||
32
entities/items/weapons.py
Normal file
32
entities/items/weapons.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import random as _random
|
||||
from entities.items import item as _item
|
||||
from entities.items import weapon_syms as _syms
|
||||
|
||||
class BrSimWeapon(_item.BrSimItem):
|
||||
|
||||
def __init__(self, wtype= None):
|
||||
self.weapon= _syms.WEAPONS[wtype or _random.randint(1,2)]
|
||||
self.name= self.weapon['name']
|
||||
self.damage= self.weapon['damage']
|
||||
self.weight= self.weapon['weight']
|
||||
self.range= self.weapon['range']
|
||||
self.ammons= self.weapon['ammons']
|
||||
self.miss_chance= self.weapon['miss_chance']
|
||||
|
||||
def _ammons_check(self):
|
||||
if self.ammons == -1: return True # this weapons doesn't needs ammons
|
||||
return self.ammons > 0
|
||||
|
||||
def _try_to_hit(self):
|
||||
if not self.miss_chance: return True
|
||||
rnd= _random.randint(0, 100)
|
||||
if rnd > self.miss_chance: return True
|
||||
return False
|
||||
|
||||
def hit(self, hits= 1):
|
||||
if not _ammons_check: return 0
|
||||
if not _try_to_hit(): return 0
|
||||
return self.damage
|
||||
|
||||
def add_ammons(self, ammons):
|
||||
self.ammons+= ammons
|
||||
Reference in New Issue
Block a user