Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6 statistic class improvement #8

Merged
merged 17 commits into from
Jul 26, 2022
Merged
54 changes: 54 additions & 0 deletions .vscode/NQTR-Statistic.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"DRincs Get Character Statistic": {
"scope": "renpy",
"prefix": "DR_StatisticGet",
"body": [
"$ {1}_{3} = ${1:mc}${2:Statistic}.get(\"${3:strength}\")",
"",
],
"description": "Get Relation Name By Character"
},
"DRincs Set Character Statistic": {
"scope": "renpy",
"prefix": "DR_StatisticSet",
"body": [
"$ ${1:mc}${2:Statistic}.set(\"${3:strength}\", ${4:1})",
"",
],
"description": "Set Character Statistic"
},
"DRincs Improvment Character Statistic": {
"scope": "renpy",
"prefix": "DR_StatisticImprovment",
"body": [
"$ ${1:mc}${2:Statistic}.improve(name = \"${3:strength}\", amt = ${4:1}, max = 10, min = 0, show_notify= True)",
"",
],
"description": "Improvment Character Statistic"
},
"DRincs Challenge Character Statistic": {
"scope": "renpy",
"prefix": "DR_StatisticChallenge",
"body": [
"$ ${1}_${3} = ${1:mc}${2:Statistic}.get(\"${3:strength}\")",
"$ ${4}_${3} = ${4:ch}${2}.get(\"${3}\")",
"if isGreaterThan(${1}_${3}, ${4}_${3} ): # ${1}_${3} > ${4}_${3}",
" \"You have won\"",
"else:",
" \"You lost\"",
"",
],
"description": "Challenge Character Statistic"
},
"DRincs Compare Menu Character Statistic": {
"scope": "renpy",
"prefix": "DR_StatisticCompareMenu",
"body": [
"$ ${1}_${3} = ${1:mc}${2:Statistic}.get(\"${3:strength}\")",
"menu:",
" \"${4:Can ...}\" if isGreaterThan(${1}_${3}, ${5:0}): # ${1}_${3} > 0",
" ",
],
"description": "Compare Menu Character Statistic"
},
}
281 changes: 148 additions & 133 deletions game/script.rpy

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ init python:
mp_ndata = MultiPersistent("namedata.f95zone.to")

from typing import Optional
from typing import Literal

class CharacterInfo():
"""Wiki: https://github.com/DRincs-Productions/DS-toolkit/wiki/Information """

def __init__(self,
def __init__(
self,
name: str,
gender: GENDER_TYPE,
sname:Optional[str]=None,
age:Optional[int]=None,
relationships:dict[Character, str]=None,
other_values:dict[Character, str]=None,):
other_values:dict[Character, str]=None,
):
# I use a dictionary because it is the best solution for compatibility and not to create variables that may not be used.
self.memory = {}
self.memory.update(other_values if other_values else {})
Expand Down
72 changes: 72 additions & 0 deletions game/tool/character_statistics.rpy
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
init 9 python:
from typing import Optional

class Statistic(object):
"""Wiki: https://github.com/DRincs-Productions/DS-toolkit/wiki/Statistic """

def __init__(
self,
values: Optional[dict[str, int]] = None,
notify_increase_dict: Optional[dict[str]] = None,
notify_decrease_dict: Optional[dict[str]] = None,
notify_dict: Optional[dict[str, NotifyEx]] = None,
):

self.memory = {}
self.memory.update(values if values else {})
self.notify_increase_dict = notify_increase_dict if notify_increase_dict else {}
self.notify_decrease_dict = notify_decrease_dict if notify_decrease_dict else {}
self.notify_dict = notify_dict if notify_dict else {}

def set(self, name: str, value: int) -> None:
"""Wiki: https://github.com/DRincs-Productions/DS-toolkit/wiki/Statistic#set """
if (name != None and name != ""):
self.memory[name] = value
else:
self.remove(name)
return

def remove(self, name: str) -> None:
"""Delete the name value"""
del self.memory[name]
return

def improve(self, name: str, amt: int = 1, max=100, min=0, show_notify= True) -> None:
"""Wiki: https://github.com/DRincs-Productions/DS-toolkit/wiki/Statistic#improvment """
if (self.get(name) != None):
if (amt > 0 and self.memory[name] >= max):
return
elif (amt < 0 and self.memory[name] <= min):
return
self.memory[name] += amt
if self.memory[name] < min:
self.memory[name] = min
elif self.memory[name] > max:
self.memory[name] = max
else:
if (amt is int and amt >= max):
self.set(name, max)
return
elif (amt is int and amt <= min):
self.set(name, min)
return
self.set(name, amt)
if show_notify:
self.notify(name = name,amt= amt)
return

def get(self, name):
"""Wiki: https://github.com/DRincs-Productions/DS-toolkit/wiki/Statistic#get """
if name in self.memory:
return self.memory[name]
else:
return None

def notify(self, name: str, amt: int) -> None:
if amt < 0 and name in self.notify_decrease_dict:
notify(self.notify_decrease_dict[name])
elif amt > 0 and name in self.notify_increase_dict:
notify(self.notify_increase_dict[name])
elif name in self.notify_dict:
notify(self.notify_dict[name])
return
Loading