Skip to content

Commit dd114db

Browse files
committed
Rejoice!
1 parent ccee1d3 commit dd114db

17 files changed

+99
-350
lines changed

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ CharActor.egg-info
44
dist/
55
.idea
66
__pycache__
7-
__pycache__/*
7+
*/__pycache__/*
88
.monster
99
character_bank/
10-
*.pyc
10+
*.pyc
11+
*.log

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12-dev

CharActor/README.md

+34-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
# Import CharActor as ca
22

33
Importing `CharActor as ca` is just a convention. But it's a good one. It's short and sweet. Upon doing so you are granted public access to the following:
4-
4+
55
* `ca.character_bank` - The character bank will have no public attributes until you create a character.
6-
* `ca.create` - The create function can, you guessed it, create a character. It accepts a number of parameters, but none are necessary, they are as follows; `obj_name`, `name`, `role`, `race`, `background`, `alignment` and `grid`.
7-
`obj_name` will designate the identifier assigned to `ca.character_bank`.
8-
* `ca.load_dict` - The load_dict function can be used to load one of the many json file is the `CharActor/_charactor/actor/dicts/` directory. It accepts a single parameter, `dict_name`, which is the name of the json file you wish to load.
9-
* `ca.load_list` - See above, but for lists saved as json.
10-
* `ca.load_dicts` - Returns a dictionary of all the json files.
11-
* `ca.Catalogues` - Provides access to the `ca.Catalogues.get` method, which can be used to produce an Item object from either `ca.Catalogues.Goods` or `ca.Catalogues.Armory`.
12-
13-
## Creating a Character
6+
* `ca.create` - The create function can, you guessed it, create a character. It accepts a number of parameters, but none are necessary, they are as follows; `obj_name`, `name`, `role`, `race`, `background`, `alignment` and `grid`.
7+
8+
## ca.create()
9+
1410
Creating a character is easy. You can do it in one line. But first, let's look at the parameters.
1511

16-
* `obj_name` - This is the identifier that will be assigned to the character. It is not necessary, but it is recommended. If you do not provide one, the character will be assigned a sequenced identifier, (e.g. `char1`, `char2`, etc.)
17-
* `name` - The name of the character. Will default to 'Unnamed' if not provided.
12+
* `obj_name` - This is the identifier that will be assigned to the character. It is not necessary, but it is recommended. If you do not provide one, the character will be assigned a sequenced identifier, (e.g. `char1`, `char2`, etc.)
13+
* `name` - The name of the character will default to 'Unnamed' if not provided.
1814
* `role` - A string, representative of the character's role(traditionally referred to as 'class'). Will be randomly selected if not provided. The available roles are as follows:
1915
* 'Barbarian'
2016
* 'Bard'
@@ -38,7 +34,7 @@ Creating a character is easy. You can do it in one line. But first, let's look a
3834
* 'Halfling'
3935
* 'Human'
4036
* 'Tiefling'
41-
* `background` - A string, representative of the character's background. Will be randomly selected if not provided. The available backgrounds are as follows:
37+
* `background` - A string, representative of the character's background. Will be randomly selected if not provided. The available backgrounds are as follows:
4238
* 'Acolyte'
4339
* 'Charlatan'
4440
* 'Criminal'
@@ -52,7 +48,7 @@ Creating a character is easy. You can do it in one line. But first, let's look a
5248
* 'Sailor'
5349
* 'Soldier'
5450
* 'Urchin'
55-
* `alignment` - A string, representative of the character's alignment. Will be randomly selected if not provided. The available alignments are as follows:
51+
* `alignment` - A string, representative of the character's alignment. Will be randomly selected if not provided. The available alignments are as follows:
5652
* 'Lawful Good'
5753
* 'Neutral Good'
5854
* 'Chaotic Good'
@@ -67,7 +63,7 @@ Creating a character is easy. You can do it in one line. But first, let's look a
6763

6864
Depending on your shell, you may be able to use tab completion once you've created a character. If you're using a shell that doesn't support tab completion, you can use the `dir` function to see what attributes are available to you. Upon creating an a character instance, if you prepare a statement with the character's identifier, followed by a period, and then press tab, you will be presented with a list of attributes and methods available to you.
6965

70-
#### Example
66+
### ca.create() Example
7167

7268
```python
7369
>>> import CharActor as ca
@@ -81,4 +77,27 @@ char1.Custom char1.actions char1.end_turn() char1.invento
8177
char1.Dexterity char1.age char1.entity_id char1.level char1.scene
8278
char1.Good char1.armor_class char1.events char1.look_around() char1.skill_points
8379
char1.Halfling char1.attack() char1.experience char1.move( char1.skillbook
84-
```
80+
```
81+
82+
Some of the attributes you will see are dynamically generated based on the parameters(see above) you provided when creating the character. For example, if you created a character with the role of 'Bard', you will see the attribute `char1.Bard`. This dynamic attribute has a static counterpart, which is always available. For example, `char1.Bard` and `char1._Role` are the same attribute. The dynamic attributes are there for convenience.
83+
84+
## ca.character_bank
85+
86+
The character bank is a dictionary of all the characters you've created. You can access it directly, but it's recommended that you use the `ca.character_bank` attribute instead. The character bank is a dictionary of character instances, with the keys being the identifiers you assigned to them. For example, if you created a character with the identifier of 'char1', you can access it by calling `ca.character_bank.char1`. You can easily assign a character to a new variable using the usual syntax. For example, `char1 = ca.character_bank.char1`.
87+
88+
### ca.character_bank Example
89+
90+
```python
91+
>>> import CharActor as ca
92+
>>> ca.create() # Creates a character with the identifier 'char1'
93+
>>> char1 = ca.character_bank.char1
94+
>>> char1.name
95+
'Unnamed'
96+
>>> char1.name = 'Bob'
97+
>>> char1.name
98+
'Bob'
99+
```
100+
101+
## Using CharActor with other modules
102+
103+
CharActor is designed to be used in conjunction with gridengine_framework, CharObj, CharTask,

CharActor/__init__.py

+34-34
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,48 @@
22
from .__log__ import logger, log
33
from ._charactor.dicts import load_all_dicts, load_dict, load_list
44
from ._charactor import create, BaseCharacters as _BaseCharacters, character_bank
5-
6-
from CharObj import Armory as _Armory, Goods as _Goods, get_item as _get_item
5+
from ._charactor.actor._actor.base_actor import BaseActor as _BaseActor, BaseCharacter as Charactor
6+
# from CharObj import Armory as _Armory, Goods as _Goods, get_item as _get_item
77
#from ._objects._items import _Armory, _Goods
88

99
log('Initializing CharActor.')
1010
log('Initializing character bank.')
1111

1212

13-
class _Catalogues:
14-
log('Initializing catalogues.')
15-
Armory = None
16-
Goods = None
13+
# class _Catalogues:
14+
# log('Initializing catalogues.')
15+
# Armory = None
16+
# Goods = None
1717

18-
def __init__(self):
19-
self.Armory = _Armory
20-
self.Goods = _Goods
21-
self.Item_Bank = []
18+
# def __init__(self):
19+
# self.Armory = _Armory
20+
# self.Goods = _Goods
21+
# self.Item_Bank = []
2222

23-
def get_item(self, term):
24-
return _get_item(term)
25-
26-
def get(self, item_name: str = None, grid=None, cell=None):
27-
if item_name is None:
28-
return
29-
if None not in [grid, cell] and isinstance(cell, str):
30-
cell = grid[cell]
31-
item_name = item_name
32-
if item_name in self.Armory:
33-
item = self.Armory.get(item_name, grid, cell)
34-
self.Item_Bank.append(item)
35-
return item
36-
elif item_name in self.Goods:
37-
item = self.Goods.get(item_name, grid, cell)
38-
self.Item_Bank.append(item)
39-
return item
40-
else:
41-
print(f'Item {item_name} not in catalogues.')
42-
return None
43-
44-
log('Creating catalogue instance.')
45-
46-
Catalogues = _Catalogues()
23+
# def get_item(self, term):
24+
# return _get_item(term)
25+
26+
# def get(self, item_name: str = None, grid=None, cell=None):
27+
# if item_name is None:
28+
# return
29+
# if None not in [grid, cell] and isinstance(cell, str):
30+
# cell = grid[cell]
31+
# item_name = item_name
32+
# if item_name in self.Armory:
33+
# item = self.Armory.get(item_name, grid, cell)
34+
# self.Item_Bank.append(item)
35+
# return item
36+
# elif item_name in self.Goods:
37+
# item = self.Goods.get(item_name, grid, cell)
38+
# self.Item_Bank.append(item)
39+
# return item
40+
# else:
41+
# print(f'Item {item_name} not in catalogues.')
42+
# return None
43+
44+
# log('Creating catalogue instance.')
45+
46+
# Catalogues = _Catalogues()
4747

4848

4949

CharActor/__log__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
_logging.addLevelName(99, 'CHARACTOR')
77
logger = _logging.getLogger('CHARACTOR')
8-
file_handler = _logging.FileHandler(f'logs/{date}.log', 'w')
8+
file_handler = _logging.FileHandler(f'logs/{date}.log', 'a')
99
formatter = _logging.Formatter('%(asctime)s - %(message)s')
1010
file_handler.setFormatter(formatter)
1111
file_handler.setLevel(99)

CharActor/_character_bank.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pickle as _pickle
2-
2+
import json as _json
33
from CharActor._quiet_dict import QuietDict as _QuietDict
44
from ._charactor.actor._actor import _character_list, _ALIGNMENTS, _BACKGROUNDS
55

@@ -10,8 +10,8 @@ class _create(_QuietDict):
1010
@staticmethod
1111
def random_character(obj_name=None, name='Unnamed'):
1212
import random as _random
13-
alignment = _random.choice(list(_ALIGNMENTS.keys()))
14-
background = _random.choice(list(_BACKGROUNDS.keys()))
13+
alignment = _random.choice(list(_ALIGNMENTS.keys()).remove('Unaligned'))
14+
background = _random.choice(list(_BACKGROUNDS.keys()).remove('Custom'))
1515
return f'{obj_name} = _Create.{_char_list[_random.randint(0, len(_char_list) - 1)]}("{name}", "{background}", "{alignment}")'
1616

1717
def __init__(self):
@@ -71,3 +71,8 @@ def _save_character(self, character, file_name):
7171
for _k in _character_list.__dict__.copy().keys():
7272
if _k not in _char_list and _k not in ['random_character', '_char_list']:
7373
delattr(_character_list, _k)
74+
75+
76+
def _load_character(file_name):
77+
with open(f'{file_name}.json') as file:
78+
chardict = _json.load(file)

CharActor/_charactor/actor/_actor/base_actor.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def tab(tabs=1):
176176
item_count += 1
177177
items = of_items()
178178
piece_of_equipment = of_equipment()
179-
return f"""A level {self.level} {self._alignment} {self._race.title} {self._role.title}
179+
return f"""A level {self.level} {self._alignment} {self._race.title} {self._role.title} {self._background.title} named {self.name}
180180
181181
{self.Strength}\tInitiative: {self.initiative}\t\tEquipment:
182182
{self.Dexterity}\tHP: {self.hp}\t\t\t{next(piece_of_equipment) if equipment_count > 0 else ''}\t\t{next(piece_of_equipment) if equipment_count > 1 else ''}\t{next(piece_of_equipment) if equipment_count > 2 else '' }\t\t{next(piece_of_equipment) if equipment_count > 3 else ''}
@@ -269,9 +269,6 @@ def __getstate__(self):
269269
del state[k]
270270
if k in ['_role', '_race', '_background', '_alignment']:
271271
state[k] = v.title
272-
if k == '_abilities':
273-
for K, V in state['_abilities'].items():
274-
state['_abilities'][K] = V.score
275272
return state
276273

277274
def __setstate__(self, state):
@@ -658,6 +655,14 @@ def _create_properties(self):
658655
else:
659656
for attr in ['movements', 'movement_queue', 'movement_energy', 'cell', 'cell_name', 'cell_history', 'last_cell', 'x', 'y', 'position', 'path']:
660657
delattr(self, attr)
658+
659+
@property
660+
def grid(self):
661+
return self._grid
662+
663+
@grid.setter
664+
def grid(self, grid):
665+
self._grid = grid
661666

662667
@property
663668
def actions(self) -> dict[str, dict[str, Any]]:
@@ -752,11 +757,11 @@ def _extracted_from_move_18(self, direction, FROM):
752757
return f'{FROM} --> {TO}'
753758

754759
def attack(self):
755-
if self.actions['attack'] != {'target': None, 'weapon': None, 'result': None}:
756-
return 'You have already attacked this turn.'
757-
elif self._target is None:
760+
# if self.actions['attack'] != {'target': None, 'weapon': None, 'result': None}:
761+
# return 'You have already attacked this turn.'
762+
if self._target is None:
758763
return 'No target.'
759-
elif hasattr(self, 'grid') and self.grid is not None and self.grid.get_distance(self.cell_name, self._target.cell_name) > self.inventory.equipment['MAIN_HAND'].range:
764+
elif hasattr(self, 'grid') and self.grid is not None and self.grid.get_distance(self.cell_name, self._target.cell_name) > self.inventory.equipment['MAIN_HAND'].weapon_range[0]:
760765
return 'Target out of range.'
761766
else:
762767
log(f'{self.name} and {self.target.name} do not inhabit a grid, so attack is emulated. Combatants are assumed to be within range of each other.')

CharActor/_charactor/actor/_actor/character/actions/__init__.py

-1
This file was deleted.

0 commit comments

Comments
 (0)