M2.6: server rules (PvP, raiding, locks and friends, death penalty, difficulty, wolf grace), chat, admin commands, server console
This commit is contained in:
@@ -275,7 +275,7 @@ func _think(dt: float) -> void:
|
||||
_state_t = 4.0
|
||||
elif d < def.attack_range and _attack_cd <= 0.0:
|
||||
_attack_cd = def.attack_cd
|
||||
player.survival.damage(def.damage, global_position, "a " + String(def.name).to_lower())
|
||||
player.survival.damage(def.damage * world.difficulty_mult("damage"), global_position, "a " + String(def.name).to_lower())
|
||||
|
||||
func _start_flee(from: Vector3) -> void:
|
||||
state = "flee"
|
||||
|
||||
@@ -53,7 +53,10 @@ func step(dt: float) -> void:
|
||||
var ex: Array[RID] = []
|
||||
if shooter != null and is_instance_valid(shooter) and shooter.has_method("get_rid"):
|
||||
ex.append(shooter.get_rid())
|
||||
var q := PhysicsRayQueryParameters3D.create(from, to, 1 | 8, ex)
|
||||
var mask := 1 | 8
|
||||
if world.server_mode and preload("res://scripts/net/rules.gd").pvp():
|
||||
mask |= 16 # other players (server_player.gd); with PvP off arrows pass through them
|
||||
var q := PhysicsRayQueryParameters3D.create(from, to, mask, ex)
|
||||
var hit := get_world_3d().direct_space_state.intersect_ray(q)
|
||||
if not hit.is_empty():
|
||||
_on_hit(hit)
|
||||
@@ -69,6 +72,15 @@ func _on_hit(hit: Dictionary) -> void:
|
||||
if visual:
|
||||
queue_free()
|
||||
return
|
||||
if c != null and c.get("player_id") != null and c.get("survival") != null:
|
||||
# Another player, on a server with PvP on.
|
||||
var k := clampf(velocity.length() / _start_speed, 0.4, 1.0)
|
||||
var by: String = String(shooter.display) if shooter != null and is_instance_valid(shooter) and shooter.get("display") != null else "an arrow"
|
||||
(c as Node).survival.damage(damage * k, global_position - dir, by)
|
||||
Actions.tell(shooter, "Hit %s" % String(c.display))
|
||||
var at: Vector3 = (c as Node3D).global_position + Vector3(0, 0.05, 0)
|
||||
_drop(Transform3D(Basis(Vector3.UP, randf() * TAU) * Basis(Vector3.FORWARD, PI * 0.5), at))
|
||||
return
|
||||
if c != null and (c as Node).is_in_group("creature"):
|
||||
var k := clampf(velocity.length() / _start_speed, 0.4, 1.0)
|
||||
Actions.projectile_hit(shooter, c, damage * k, global_position, item_id if item_id == "arrow" else "")
|
||||
|
||||
@@ -122,7 +122,7 @@ func _attack(pp: Vector3, d: float, as_state: String) -> void:
|
||||
steer(atan2(-to.x, -to.z))
|
||||
if d < def.attack_range and _attack_cd <= 0.0 and _can_reach_player():
|
||||
_attack_cd = def.attack_cd
|
||||
player.survival.damage(def.damage, global_position, "a " + String(def.name).to_lower())
|
||||
player.survival.damage(def.damage * world.difficulty_mult("damage"), global_position, "a " + String(def.name).to_lower())
|
||||
if as_state == "lunge":
|
||||
state = "retreat"
|
||||
_state_t = 1.6
|
||||
|
||||
@@ -67,14 +67,22 @@ func is_night() -> bool:
|
||||
var h: float = world.day_night.hours()
|
||||
return h >= 19.5 or h < 5.5
|
||||
|
||||
static func pack_size(day: int) -> int:
|
||||
if day < DEN_DAY:
|
||||
## The pack grows 3 and 6 days after it arrives (2, 3, then 4 wolves), plus
|
||||
## or minus one for a server's difficulty.
|
||||
func pack_size(day: int) -> int:
|
||||
if day < den_day:
|
||||
return 0
|
||||
if day < 6:
|
||||
return 2
|
||||
if day < 9:
|
||||
return 3
|
||||
return 4
|
||||
var n := 4
|
||||
if day < den_day + 3:
|
||||
n = 2
|
||||
elif day < den_day + 6:
|
||||
n = 3
|
||||
return clampi(n + pack_bonus, 1, 5)
|
||||
|
||||
## The schedule (a server sets it from its rules; single-player keeps 3/4).
|
||||
var den_day := DEN_DAY
|
||||
var hunt_day := HUNT_DAY
|
||||
var pack_bonus := 0
|
||||
|
||||
func alive() -> Array:
|
||||
var out := []
|
||||
@@ -95,8 +103,8 @@ func step(dt: float) -> void:
|
||||
var day := effective_day()
|
||||
var night := is_night()
|
||||
var want := "none"
|
||||
if day >= DEN_DAY:
|
||||
want = "hunt" if night and day >= HUNT_DAY else "den"
|
||||
if day >= den_day:
|
||||
want = "hunt" if night and day >= hunt_day else "den"
|
||||
if want != mode:
|
||||
_enter(want, day)
|
||||
if mode == "none":
|
||||
@@ -123,7 +131,7 @@ func step(dt: float) -> void:
|
||||
m.global_position = den.slot_pos(m.slot)
|
||||
m.wounded = false
|
||||
m.state = "rest"
|
||||
if night and day >= DEN_DAY:
|
||||
if night and day >= den_day:
|
||||
_howl_left -= dt
|
||||
if _howl_left <= 0.0:
|
||||
_howl_left = _rng.randf_range(50.0, 110.0)
|
||||
@@ -148,9 +156,9 @@ func _warn(day: int) -> void:
|
||||
if _warned.has(day):
|
||||
return
|
||||
_warned[day] = true
|
||||
if day == DEN_DAY:
|
||||
if day == den_day:
|
||||
Actions.tell_all("Wolves are howling up in the hills. They'll come hunting soon.")
|
||||
elif day == HUNT_DAY:
|
||||
elif day == hunt_day:
|
||||
Actions.tell_all("The wolves are hunting tonight. Stay near a fire or behind closed walls.")
|
||||
_howl_left = _rng.randf_range(2.0, 6.0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user