145 lines
3.3 KiB
Go
145 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"math"
|
|
"math/rand"
|
|
"strconv"
|
|
)
|
|
|
|
type item struct {
|
|
kind int
|
|
match *match
|
|
owner *client
|
|
}
|
|
|
|
func (i *item) name() string {
|
|
switch i.kind {
|
|
case 0:
|
|
return "Saw"
|
|
case 1:
|
|
return "Beer"
|
|
case 2:
|
|
return "Phone"
|
|
case 3:
|
|
return "Magnifying glass"
|
|
case 4:
|
|
return "Expired medicine"
|
|
case 5:
|
|
return "Cigarette pack"
|
|
case 6:
|
|
return "Inverter"
|
|
case 7:
|
|
return "Adrenaline"
|
|
default:
|
|
return "None"
|
|
}
|
|
}
|
|
|
|
func (i *item) useItem(param1 int) {
|
|
successfully := false
|
|
if i.owner.isHost != i.owner.match.guestsTurn {
|
|
|
|
successfully = true
|
|
switch i.kind {
|
|
case 0:
|
|
i.match.gun.doubled = true
|
|
i.match.sendMessage("I doubled the damage for 1 round by sawing the shotgun", i.owner)
|
|
break
|
|
|
|
case 1:
|
|
i.match.gun.rack()
|
|
i.match.sendMessage("I rack the magazine", i.owner)
|
|
i.match.announceRounds()
|
|
break
|
|
|
|
case 2:
|
|
roundIndex := rand.Intn(len(i.match.gun.magazine) - 2)
|
|
round := i.match.gun.magazine[roundIndex]
|
|
roundString := ""
|
|
if round {
|
|
roundString = "live"
|
|
} else {
|
|
roundString = "blank"
|
|
}
|
|
roundForPlayer := int(math.Abs(float64(len(i.match.gun.magazine) - 2 - roundIndex)))
|
|
i.match.sendMessage("I used a phone", i.owner)
|
|
i.owner.send("The " + strconv.Itoa(roundForPlayer) + " round from now is " + roundString)
|
|
break
|
|
|
|
case 3:
|
|
round := i.match.gun.magazine[len(i.match.gun.magazine)-1]
|
|
roundString := ""
|
|
if round {
|
|
roundString = "live"
|
|
} else {
|
|
roundString = "blank"
|
|
}
|
|
i.match.sendMessage("I used a magnifying glass", i.owner)
|
|
i.owner.send("Next round is " + roundString)
|
|
break
|
|
|
|
case 4:
|
|
if rand.Int63()&(1<<62) == 0 {
|
|
for cnt := 0; cnt < 2; cnt++ {
|
|
if i.owner.HP < i.match.maxHP {
|
|
i.owner.HP++
|
|
}
|
|
}
|
|
} else {
|
|
i.owner.HP--
|
|
i.match.announceHP()
|
|
i.match.checkStatus()
|
|
}
|
|
i.match.sendMessage("I used an expired medicine", i.owner)
|
|
i.match.announceHP()
|
|
break
|
|
|
|
case 5:
|
|
if i.owner.HP < i.match.maxHP {
|
|
i.owner.HP++
|
|
}
|
|
i.match.sendMessage("I used a pack of cigarettes", i.owner)
|
|
i.match.announceHP()
|
|
break
|
|
|
|
case 6:
|
|
i.match.gun.magazine[len(i.match.gun.magazine)-1] = !i.match.gun.magazine[len(i.match.gun.magazine)-1]
|
|
i.match.sendMessage("I used an inverter", i.owner)
|
|
break
|
|
case 7:
|
|
var otherPlayer *client
|
|
if i.owner.isHost {
|
|
otherPlayer = i.match.guest
|
|
} else {
|
|
otherPlayer = i.match.host
|
|
}
|
|
if param1 < len(otherPlayer.items) {
|
|
i.owner.items = append(i.owner.items, otherPlayer.items[param1])
|
|
otherPlayer.items = append(otherPlayer.items[:param1], otherPlayer.items[param1:]...)
|
|
itemName := otherPlayer.items[param1].name()
|
|
if itemName[0] == 'a' || itemName[0] == 'e' || itemName[0] == 'i' || itemName[0] == 'o' || itemName[0] == 'u' || itemName[0] == 'y' {
|
|
itemName = " an " + itemName
|
|
} else {
|
|
itemName = " a " + itemName
|
|
}
|
|
i.match.sendMessage("I stole from "+otherPlayer.Username+"("+strconv.Itoa(otherPlayer.ID)+")"+itemName, i.owner)
|
|
} else {
|
|
i.owner.send("This requires another parameter")
|
|
successfully = false
|
|
}
|
|
break
|
|
}
|
|
} else {
|
|
i.owner.send("It is not your turn")
|
|
}
|
|
if successfully {
|
|
for cnt, item := range i.owner.items {
|
|
if item.kind == i.kind {
|
|
i.owner.items = append(i.owner.items[:cnt], i.owner.items[cnt+1:]...)
|
|
break
|
|
}
|
|
}
|
|
i.match.announceItems()
|
|
}
|
|
}
|