bugfix, strike nerf, better logic

This commit is contained in:
wr34k 2018-07-03 22:14:38 +02:00
parent 69c7f0de1f
commit 005a6cfbed
8 changed files with 119 additions and 100 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import random, json, os import random, json, os, time
from fighter import Fighter from fighter import Fighter
@ -177,19 +177,19 @@ class Fight(object):
if f.stance == e.stance == 'ground': if f.stance == e.stance == 'ground':
dmg = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance][e.groundPos]['dmgidx'] dmg = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance][e.groundPos]['dmgidx']
mindmg = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance][e.groundPos]['mindmg'] mindmg = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance][e.groundPos]['mindmg']
blockidx = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance][e.groundPos]['blockidx']
fallchance = 0 fallchance = 0
texts = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance][e.groundPos]['text'] missluck = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance][e.groundPos]['missluck']
texts = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance][e.groundPos]['text']
else: else:
dmg = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['dmgidx'] dmg = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['dmgidx']
mindmg = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['mindmg'] mindmg = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['mindmg']
blockidx = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['blockidx']
fallchance = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['fallchance'] \ fallchance = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['fallchance'] \
if 'fallchance' in self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance] \ if 'fallchance' in self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance] \
else 0 else 0
texts = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['text'] missluck = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['missluck']
texts = self.config['moves'][f.stance][f.nextAction[0]][f.nextAction[1]][e.stance]['text']
return dmg, mindmg, blockidx, fallchance, texts return dmg, mindmg, fallchance, missluck, texts
def attack(self): def attack(self):
roll1 = roll2 = 0 roll1 = roll2 = 0
@ -228,7 +228,7 @@ class Fight(object):
if attacker.groundPos == 'below': if attacker.groundPos == 'below':
attacker.groundPos = 'above' attacker.groundPos = 'above'
defender.groundPos = 'below' defender.groundPos = 'below'
self.shout("{} Manage to get above {}!".format( \ self.shout("{} manages to get above {}!".format( \
self.IRC.mirc.color(attacker.nick, attacker.colour), \ self.IRC.mirc.color(attacker.nick, attacker.colour), \
self.IRC.mirc.color(defender.nick, defender.colour) \ self.IRC.mirc.color(defender.nick, defender.colour) \
)) ))
@ -236,10 +236,11 @@ class Fight(object):
if attacker.nextAction[0] == 'standup': if attacker.nextAction[0] == 'standup':
standchance = self.config['moves'][attacker.stance]['standup'][defender.stance]['chance'] standchance = self.config['moves'][attacker.stance]['standup'][defender.stance]['chance']
else: else:
dmg, mindmg, blockidx, fallchance, texts = self.get_next_move_data(attacker, defender) dmg, mindmg, fallchance, missluck, texts = self.get_next_move_data(attacker, defender)
realdmg = (random.random() * dmg) + mindmg
txt = self.prettyTxt(attacker, defender, texts) txt = self.prettyTxt(attacker, defender, texts)
self.shout("{}".format(txt))
blockchance = 0 blockchance = 0
if defender.nextAction[0] == 'block': if defender.nextAction[0] == 'block':
@ -248,26 +249,32 @@ class Fight(object):
blocktxts = self.config["moves"][defender.stance][defender.nextAction[0]][defender.nextAction[1]]["text"] blocktxts = self.config["moves"][defender.stance][defender.nextAction[0]][defender.nextAction[1]]["text"]
if (random.random() * 100) < blockchance * (blockidx / 100): if (random.random() * 100) < blockchance:
blocktxt = self.prettyTxt(attacker, defender, blocktxts) blocktxt = self.prettyTxt(attacker, defender, blocktxts)
self.shout("{}".format(blocktxt)) self.shout("{}".format(txt))
self.shout("{}".format(blocktxt))
else: else:
if defender.nextAction[0] == 'block': if (random.random()*100) < missluck:
self.shout("{} Tryed to block {} but failed miserably!".format(self.IRC.mirc.color(defender.nick, defender.colour), defender.nextAction[1])) self.shout("{}".format(txt))
self.shout("{} failed to hit {}!".format(self.IRC.mirc.color(attacker.nick, attacker.colour), self.IRC.mirc.color(defender.nick, defender.colour)))
defender.advantage = True
attacker.advantage = False
else:
txt += " | (- {} hp)".format(self.IRC.mirc.color(int(realdmg), self.IRC.mirc.colors.YELLOW))
self.shout("{}".format(txt))
if defender.nextAction[0] == 'block':
self.shout("{} tried to block {} but failed miserably!".format(self.IRC.mirc.color(defender.nick, defender.colour), defender.nextAction[1]))
defender.hp -= realdmg
realdmg = (random.random() * dmg) + mindmg if (random.random() * 100) < fallchance: # defender falls down?
defender.stance = 'ground'
defender.hp -= realdmg if attacker.stance == 'ground':
defender.groundPos = 'above'
if (random.random() * 100) < fallchance: # defender falls down? else:
defender.stance = 'ground' defender.groundPos = 'below'
if attacker.stance == 'ground': falltxt = self.prettyTxt(attacker, defender, self.config['info']['stand2ground'])
defender.groundPos = 'above' self.shout("{}".format(falltxt))
else:
defender.groundPos = 'below'
falltxt = self.prettyTxt(attacker, defender, self.config['info']['stand2ground'])
self.shout("{}".format(falltxt))
if defender.hp <= 0: if defender.hp <= 0:
@ -304,15 +311,20 @@ class Fight(object):
self.IRC.privmsg(self.IRC.channel, msg) self.IRC.privmsg(self.IRC.channel, msg)
def updatePalmares(self, winner, looser): def updatePalmares(self, winner, looser):
if not os.path.isfile(PALMARES_FILE):
open(PALMARES_FILE, "x").close()
mode = "r" if os.path.exists(PALMARES_FILE) else "w+" with open(PALMARES_FILE, "r") as f:
with open(PALMARES_FILE, mode) as f:
try: try:
palmares = json.loads(f.read()) data = f.read()
palmares = {}
if data:
palmares = json.loads(data)
except Exception as e: except Exception as e:
self.IRC.log.error("Error in json.loads() backuping palmares file to {}.bkp".format(PALMARES_FILE), e) tNow = int(time.time())
self.IRC.log.error("Error in json.loads() backuping palmares file to {}.{}.bkp".format(PALMARES_FILE, tNow), e)
from shutil import copyfile from shutil import copyfile
copyfile(PALMARES_FILE, "{}.bkp".format(PALMARES_FILE)) copyfile(PALMARES_FILE, "{}.{}.bkp".format(PALMARES_FILE, tNow))
palmares = {} palmares = {}
if winner.nick not in palmares: if winner.nick not in palmares:

View File

@ -1,5 +1,5 @@
# IRCUFC # IRCUFC
WORK IN PROGRESS **WORK IN PROGRESS**
IRC Game to let chatters having UFC like fights. IRC Game to let chatters having UFC like fights.
@ -7,32 +7,31 @@ IRC Game to let chatters having UFC like fights.
Connect to #IRCUFC @ Efnet and type !fight to register to the next fight Connect to #IRCUFC @ Efnet and type !fight to register to the next fight
once 2 fighters will be registered, you'll reveice a list of actions possible for you to do in the next turn. once 2 fighters will be registered, you'll reveice a list of actions possible for you to do in the next turn. (kick high, punch middle, ...)
To register an action for the next turn, simply use !action following by the action (ex: !action kick high)
Once a fighter have no hp left, the fight is over. Once a fighter have no hp left, the fight is over.
### How to run:
```
python3 main.py
```
### General Commands:
* **!fight** -- Register for the next fight
* **!status** -- Get current status of the fight (If sent as PM to the bot, you'll get more information like your next move)
* **!action** -- Register your next action (ex: !action kick high, !action block middle, !action standup)
### Admin Commands:
* **!cancel** -- Cancel the current fight
If both fighters are attacking at the same time, then the one who will hit is random. There's still an slight advantage to the last player having hit.
using 'block' will greatly increase the chance of blocking a hit. be careful though, if for instance you block high and your opponent attacks you low or middle, you'll have 100% chance of taking the hit. If you succeed to block a hit, you'll take the advantage for the next turn.
There's a chance for fighters to fall down. In this case, hits will be much less powerful, and your opponent will do huge damage. You'll have to use the 'standup' action in order to .. stand up :) This action will make you vulnerable to a hit. ### More Info:
If both fighters are attacking at the same time, then the one who will hit is random. There's still an slight advantage to the last player having hit. Also, some attacks have more chance to fail, but those ones are usually more powerful.
TODO LIST:
Fix shitty code (!!!)
Add better output (Colors, formatting)
Add submissions
Add more strikes? (Superman punch, spinning kicks)
Add ascii art to display at each turn
IDEAS:
Add a betting system, where spectators can bet for the next fight
Add XP system, where each fight let you get stronger / more resistant / get more moves
Using 'block' with the right level (high, middle, low) will give you a great chance to block the next hit. If so, you won't loose HP, and you'll take the advantage for the next round.. Be careful though, if for instance you block high and your opponent attacks you low or middle, you'll have 100% chance of taking the hit (Except if the strike fails). Blocking chance depend on your stance.
There's a chance for fighters to fall down. In this case, hits will be much less powerful, and your opponent will do huge damage. If both fighters are on the ground, then one of them will be above the other. (The second fighter to fall will be above. Then, the one with the advantage will be above.) You'll have to use the '**!action standup**' command in order to .. stand up :)

8
TODO Normal file
View File

@ -0,0 +1,8 @@
TODO LIST:
Add submissions
Fix shitty code (!!!)
Add ascii art to display at each turn
Add better output (Colors, formatting)
Add more strikes? (Superman punch, spinning kicks)
Add a betting system, where spectators can bet for the next fight
Add XP system, where each fight let you get stronger / more resistant / get more moves (??)

View File

@ -21,18 +21,18 @@
"kick": { "kick": {
"high": { "high": {
"stand": { "stand": {
"dmgidx": 40, "dmgidx": 30,
"mindmg": 20, "mindmg": 20,
"fallchance": 5, "fallchance": 5,
"blockidx": 50, "missluck": 30,
"text": [ "text": [
"%attacker% head kicks %defender%" "%attacker% head kicks %defender%"
] ]
}, },
"ground": { "ground": {
"dmgidx": 60, "dmgidx": 45,
"mindmg": 25, "mindmg": 25,
"blockidx": 28, "missluck": 20,
"text": [ "text": [
"%attacker% stomps %defender% in the head!" "%attacker% stomps %defender% in the head!"
] ]
@ -40,18 +40,18 @@
}, },
"middle": { "middle": {
"stand": { "stand": {
"dmgidx": 30, "dmgidx": 20,
"mindmg": 10, "mindmg": 10,
"fallchance": 8, "fallchance": 8,
"blockidx": 38, "missluck": 20,
"text": [ "text": [
"%attacker% middle kicks %defender%" "%attacker% middle kicks %defender%"
] ]
}, },
"ground": { "ground": {
"dmgidx": 45, "dmgidx": 30,
"mindmg": 20, "mindmg": 20,
"blockidx": 32, "missluck": 10,
"text": [ "text": [
"%attacker% stomps %defender% in the body!" "%attacker% stomps %defender% in the body!"
] ]
@ -59,18 +59,18 @@
}, },
"low": { "low": {
"stand": { "stand": {
"dmgidx": 23, "dmgidx": 13,
"mindmg": 5, "mindmg": 5,
"fallchance": 15, "fallchance": 15,
"blockidx": 35, "missluck": 22,
"text": [ "text": [
"%attacker% low kicks %defender%" "%attacker% low kicks %defender%"
] ]
}, },
"ground": { "ground": {
"dmgidx": 30, "dmgidx": 10,
"mindmg": 15, "mindmg": 5,
"blockidx": 40, "missluck": 12,
"text": [ "text": [
"%attacker% kicks %defender%'s legs while %defender% is on the ground" "%attacker% kicks %defender%'s legs while %defender% is on the ground"
] ]
@ -80,10 +80,10 @@
"punch": { "punch": {
"high": { "high": {
"stand": { "stand": {
"dmgidx": 30, "dmgidx": 18,
"mindmg": 10, "mindmg": 12,
"fallchance": 2, "fallchance": 2,
"blockidx": 30, "missluck": 25,
"text": [ "text": [
"%attacker% head punches %defender%" "%attacker% head punches %defender%"
] ]
@ -91,10 +91,10 @@
}, },
"middle": { "middle": {
"stand": { "stand": {
"dmgidx": 20, "dmgidx": 10,
"mindmg": 5, "mindmg": 6,
"fallchance": 4, "fallchance": 4,
"blockidx": 21, "missluck": 10,
"text": [ "text": [
"%attacker% punches %defender% to the body" "%attacker% punches %defender% to the body"
] ]
@ -139,27 +139,27 @@
"kick": { "kick": {
"high": { "high": {
"stand": { "stand": {
"dmgidx": 30, "dmgidx": 15,
"mindmg": 10, "mindmg": 10,
"fallchance": 8, "fallchance": 8,
"blockidx": 58, "missluck": 40,
"text": [ "text": [
"%attacker% head kicks %defender% from the ground!" "%attacker% head kicks %defender% from the ground!"
] ]
}, },
"ground": { "ground": {
"above": { "above": {
"dmgidx": 20, "dmgidx": 10,
"mindmg": 11, "mindmg": 14,
"blockidx": 66, "missluck": 30,
"text": [ "text": [
"%attacker% hit %defender% with kneel kicks to the head from below" "%attacker% hit %defender% with kneel kicks to the head from below"
] ]
}, },
"below": { "below": {
"dmgidx": 40, "dmgidx": 25,
"mindmg": 23, "mindmg": 20,
"blockidx": 42, "missluck": 15,
"text": [ "text": [
"%attacker% hit %defender% with huge kneel kicks to the head!" "%attacker% hit %defender% with huge kneel kicks to the head!"
] ]
@ -168,27 +168,27 @@
}, },
"middle": { "middle": {
"stand": { "stand": {
"dmgidx": 20, "dmgidx": 12,
"mindmg": 5, "mindmg": 8,
"fallchance": 5, "fallchance": 5,
"blockidx": 43, "missluck": 33,
"text": [ "text": [
"%attacker% middle kicks %defender% from the ground!" "%attacker% middle kicks %defender% from the ground!"
] ]
}, },
"ground": { "ground": {
"above": { "above": {
"dmgidx": 13, "dmgidx": 8,
"mindmg": 9, "mindmg": 3,
"blockidx": 70, "missluck": 26,
"text": [ "text": [
"%attacker% hit %defender% with kneel kicks to the body for below" "%attacker% hit %defender% with kneel kicks to the body for below"
] ]
}, },
"below": { "below": {
"dmgidx": 25, "dmgidx": 18,
"mindmg": 17, "mindmg": 15,
"blockidx": 48, "missluck": 12,
"text": [ "text": [
"%attacker% hit %defender% with kneel kicks to the body" "%attacker% hit %defender% with kneel kicks to the body"
] ]
@ -197,27 +197,27 @@
}, },
"low": { "low": {
"stand": { "stand": {
"dmgidx": 15, "dmgidx": 8,
"mindmg": 3, "mindmg": 1,
"fallchance": 18, "fallchance": 28,
"blockidx": 33, "missluck": 12,
"text": [ "text": [
"%attacker% low kicks %defender% from the ground!" "%attacker% low kicks %defender% from the ground!"
] ]
}, },
"ground": { "ground": {
"above": { "above": {
"dmgidx": 7, "dmgidx": 4,
"mindmg": 2, "mindmg": 1,
"blockidx": 65, "missluck": 22,
"text": [ "text": [
"%attacker% hit %defender% with kneel kicks to the legs from below" "%attacker% hit %defender% with kneel kicks to the legs from below"
] ]
}, },
"below": { "below": {
"dmgidx": 15, "dmgidx": 12,
"mindmg": 2, "mindmg": 8,
"blockidx": 40, "missluck": 8,
"text": [ "text": [
"%attacker% hit %defender% with kneel kicks to the legs" "%attacker% hit %defender% with kneel kicks to the legs"
] ]

View File

@ -1 +1 @@
{"wr34k": {"wins": 1, "looses": 0}, "wreek": {"wins": 0, "looses": 1}} {"wreek": {"wins": 2, "looses": 0}, "wr34k": {"wins": 0, "looses": 2}}

View File

@ -89,7 +89,7 @@ class IrcBot(object):
data = self.sock.recv(1024).decode('utf-8', 'ignore') data = self.sock.recv(1024).decode('utf-8', 'ignore')
for line in [x.split() for x in data.split("\r\n") if len(x.split()) > 1]: for line in [x.split() for x in data.split("\r\n") if len(x.split()) > 1]:
self.log.info("<< {}".format(' '.join(line))) # self.log.info("<< {}".format(' '.join(line)))
if line[0][1:] == 'ING': if line[0][1:] == 'ING':
ircEvents.eventPING(self, line) ircEvents.eventPING(self, line)

View File

@ -74,7 +74,7 @@ class IrcCommands(object):
if chan != self.IRC.channel: if chan != self.IRC.channel:
self.fight.set_next_action(nick, args) self.fight.set_next_action(nick, args)
else: else:
self.IRC.privmsg(self.IRC.channel, "{}".format(self.IRC.mirc.color("Not here retard your opponent can see your next move!", self.IRC.mirc.colors.LIGHTRED))) self.IRC.privmsg(self.IRC.channel, "{}".format(self.IRC.mirc.color("Not here retard your opponent can see your next move!", self.IRC.mirc.colors.PURPLE)))
self.IRC.flood_flag[chan] = False self.IRC.flood_flag[chan] = False