126 lines
2.3 KiB
GDScript
126 lines
2.3 KiB
GDScript
class_name Player extends Node
|
|
|
|
var gameName: String = ""
|
|
|
|
# -- HEALTH --
|
|
const maxHealth: int = 3
|
|
const minHealth: int = 0
|
|
var health := maxHealth
|
|
# -- HEALTH --
|
|
|
|
# -- Item --
|
|
var itemInventory: Array[Item] = []
|
|
# -- Item --
|
|
|
|
var gun: Gun
|
|
var selectedPlayer: Player = self
|
|
|
|
var character: Character
|
|
|
|
var bot: bool = false
|
|
var botLogic: Bot = null
|
|
|
|
signal dead(player: Player)
|
|
signal hit(player: Player)
|
|
signal missed()
|
|
signal hurt()
|
|
|
|
func _init(_name: String, _gun: Gun, _character: Character) -> void:
|
|
gameName = _name
|
|
gun = _gun
|
|
character = _character
|
|
gun.setOwner(self)
|
|
|
|
# -- HEALTH --
|
|
func damage(amount: int) -> void:
|
|
print("Hit")
|
|
if health - amount < minHealth:
|
|
kill()
|
|
health = minHealth
|
|
else:
|
|
health -= amount
|
|
for i in range(0,amount):
|
|
character.drinkShot()
|
|
|
|
func heal(amount: int) -> void:
|
|
if health + amount > maxHealth:
|
|
health = maxHealth
|
|
else:
|
|
health += amount
|
|
|
|
func getHealth () -> int:
|
|
return health
|
|
|
|
func kill():
|
|
dead.emit(self)
|
|
# -- HEALTH --
|
|
|
|
|
|
# -- Item --
|
|
func addItem(_item: Item) -> void:
|
|
itemInventory.append(_item)
|
|
|
|
func removeItem(_item: Item) -> void:
|
|
itemInventory.erase(_item)
|
|
|
|
func getItems() -> Array[Item]:
|
|
return itemInventory
|
|
# -- Item --
|
|
|
|
|
|
# -- Gun --
|
|
func giveGun(_gun: Gun):
|
|
gun = _gun
|
|
|
|
func takeGun():
|
|
gun = null
|
|
|
|
func useItem(_item: Item):
|
|
if _item is Bullet:
|
|
loadBullet(_item)
|
|
else:
|
|
print("no bullet")
|
|
|
|
func loadBullet(_bullet: Bullet):
|
|
if gun.magazin.size() < gun.magazineSize:
|
|
gun.loadBullet(_bullet)
|
|
itemInventory.erase(_bullet)
|
|
else:
|
|
print("magazine Full Full")
|
|
|
|
func shootAtSelectedPlayer():
|
|
var randomBullet = gun.getRandomBullet()
|
|
if randomBullet is StandardBullet or randomBullet is LuckyBullet:
|
|
var bulletDamage = randomBullet.getDamage()
|
|
if bulletDamage > 0:
|
|
character.shootGun(true)
|
|
selectedPlayer.damage(bulletDamage)
|
|
else:
|
|
character.shootGun(false)
|
|
#character.emitShootGunFinished()
|
|
#character.gunEmpty()
|
|
print("Missed")
|
|
else:
|
|
character.shootGun(false)
|
|
#character.gunEmpty()
|
|
print("Empty")
|
|
|
|
# -- Gun --
|
|
|
|
func selectPlayer(_player: Player) -> void:
|
|
selectedPlayer = _player
|
|
|
|
func getGameName() -> String:
|
|
return gameName
|
|
|
|
func setCharacter(_character: Character) -> void:
|
|
character = _character
|
|
|
|
func getItemAmount() -> int:
|
|
return itemInventory.size()
|
|
|
|
func isBot() -> bool:
|
|
return botLogic != null
|
|
|
|
func setBotLogic(_botLogic: Bot) -> void:
|
|
botLogic = _botLogic
|