Compare commits

..

3 Commits

7 changed files with 81 additions and 10 deletions

View File

@@ -48,10 +48,14 @@
packages = forAllSystems ( packages = forAllSystems (
{ pkgs }: { pkgs }:
let
project_file = builtins.readFile ./project.godot;
version = builtins.head (builtins.match ".*version=\"([0-9.]+)\".*" project_file);
in
{ {
slopvivors = pkgs.stdenv.mkDerivation { slopvivors = pkgs.stdenv.mkDerivation {
pname = "slopvivors"; pname = "slopvivors";
version = "0.1.0"; version = version;
src = ./.; src = ./.;
strictDeps = true; strictDeps = true;
@@ -82,7 +86,7 @@
}; };
slopvivors_web_files = pkgs.stdenv.mkDerivation { slopvivors_web_files = pkgs.stdenv.mkDerivation {
pname = "slopvivors-web-files"; pname = "slopvivors-web-files";
version = self.packages.${pkgs.system}.slopvivors.version; version = version;
src = ./.; src = ./.;
strictDeps = true; strictDeps = true;
@@ -112,7 +116,7 @@
}; };
slopvivors_web = pkgs.buildGoModule { slopvivors_web = pkgs.buildGoModule {
pname = "slopvivors-web"; pname = "slopvivors-web";
version = self.packages.${pkgs.system}.slopvivors_web.version; version = version;
vendorHash = null; vendorHash = null;
src = self.packages.${pkgs.system}.slopvivors_web_files; src = self.packages.${pkgs.system}.slopvivors_web_files;
@@ -154,8 +158,8 @@
''; '';
}; };
slopvivors_docker = pkgs.dockerTools.buildLayeredImage { slopvivors_docker = pkgs.dockerTools.buildLayeredImage {
name = "slopvivors-docker"; name = "slopvivors-docker-${version}";
tag = "${self.packages.${pkgs.system}.slopvivors.version}"; tag = version;
created = "now"; created = "now";
contents = [ contents = [
pkgs.busybox pkgs.busybox

View File

@@ -11,6 +11,7 @@ config_version=5
[application] [application]
config/name="Slopvivors" config/name="Slopvivors"
config/version="0.2.0"
run/main_scene="uid://bjg50n7aab3ng" run/main_scene="uid://bjg50n7aab3ng"
config/features=PackedStringArray("4.4", "Forward Plus") config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"

View File

@@ -29,6 +29,11 @@ func _ready() -> void:
if not weapon: if not weapon:
weapon = WEAPON_SWORD.instantiate() weapon = WEAPON_SWORD.instantiate()
add_child(weapon) add_child(weapon)
var mod = WeaponModBase.new()
mod.mod_property = "attack_damage"
mod.mod_value = 10.0
mod.mod_type = WeaponModBase.ModType.ADDITIVE
weapon.add_mod(mod)
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:

View File

@@ -1,11 +1,19 @@
class_name WeaponBase class_name WeaponBase
extends Node2D extends Node2D
enum WeaponTag {
CAN_RETURN,
CAN_BLEED,
}
@export var attack_cd: float @export var attack_cd: float
@export var attack_damage: float @export var attack_damage: float
@export var attack_aoe: float @export var attack_aoe: float
@export var attack_duration: float @export var attack_duration: float
@export var attack_range: float @export var attack_range: float
@export var attack_crit_chance: float = 0.05
@export var tags: Array[String] = []
@export var modifiers: Array[WeaponModBase] = []
@onready var active_cd_timer: Timer = $ActiveCDTimer @onready var active_cd_timer: Timer = $ActiveCDTimer
@@ -25,6 +33,10 @@ func do_active() -> void:
_do_active() _do_active()
func add_mod(mod: WeaponModBase) -> void:
modifiers.append(mod)
func _do_active() -> void: func _do_active() -> void:
push_error("%s does not implement do_active" % self) push_error("%s does not implement do_active" % self)
@@ -53,3 +65,14 @@ func find_target_in_radius() -> EnemyBase:
): ):
closest = c closest = c
return closest return closest
func get_calculated(key: String) -> Variant:
return WeaponModBase.get_calculated(self, key)
func has_property(key: String) -> bool:
for prop in get_property_list():
if prop.name == key:
return true
return false

View File

@@ -0,0 +1,36 @@
class_name WeaponModBase
extends Resource
enum ModType { ADDITIVE, MULTIPLICATIVE, ABSOLUTE, BOOL }
@export var name: String = "Unnamed mod"
@export var description: String = ""
@export var icon: Texture2D
@export var mod_property: String
@export var mod_value: float
@export var mod_value_bool: bool = false
@export var mod_type: ModType = ModType.MULTIPLICATIVE
@export var mod_extra_tags: Array[WeaponBase.WeaponTag] = []
static func get_calculated(weapon: WeaponBase, key: String) -> Variant:
assert(
weapon.has_property(key),
"tried calculate property '%s' where base value does not exist on %s" % [key, weapon]
)
var base_value = weapon.get(key)
var add = 0.0
var mul = 1.0
for mod in weapon.modifiers:
if mod.mod_property == key:
match mod.mod_type:
ModType.ADDITIVE:
add += mod.mod_value
ModType.MULTIPLICATIVE:
mul *= mod.mod_value
ModType.ABSOLUTE:
return mod.mod_value
ModType.BOOL:
return mod.mod_value_bool
return (base_value + add) * mul

View File

@@ -0,0 +1 @@
uid://b1cg1bhnt6xk4

View File

@@ -44,12 +44,13 @@ func _do_active() -> void:
func deal_damage(enemy: EnemyBase, damage_mult: float): func deal_damage(enemy: EnemyBase, damage_mult: float):
var crit_chance = _player.player_stats.get_final("crit_chance", _player.modifiers) var weapon_crit = get_calculated("attack_crit_chance")
var damage_dealt = attack_damage * damage_mult var player_crit = _player.player_stats.get_final("crit_chance", _player.modifiers)
var is_crit = randf() >= 1 - crit_chance var damage = get_calculated("attack_damage")
var is_crit = randf() >= 1 - weapon_crit + player_crit
if is_crit: if is_crit:
damage_dealt *= _player.player_stats.get_final("crit_multiplier", _player.modifiers) damage *= _player.player_stats.get_final("crit_multiplier", _player.modifiers)
enemy.take_damage(damage_dealt, is_crit) enemy.take_damage(damage * damage_mult, is_crit)
func _on_projectile_hit(projectile: WeaponSwordProjectile, enemy: EnemyBase, damage_mult: float): func _on_projectile_hit(projectile: WeaponSwordProjectile, enemy: EnemyBase, damage_mult: float):