make friendly fire host option side, too weird to be client side, and probably didn't work anyways

This commit is contained in:
bgkillas 2024-08-13 17:54:37 -04:00
parent d1701413e2
commit de4d8aa77a
4 changed files with 23 additions and 24 deletions

View file

@ -62,6 +62,7 @@ pub struct GameSettings {
enemy_hp_mult: f32,
world_sync_interval: u32,
game_mode: GameMode,
friendly_fire: bool,
}
impl Default for GameSettings {
@ -77,6 +78,7 @@ impl Default for GameSettings {
enemy_hp_mult: 1.0,
world_sync_interval: 2,
game_mode: GameMode::SharedHealth,
friendly_fire: false
}
}
}
@ -129,7 +131,6 @@ struct AppSavedState {
player_color: PlayerColor,
player_picker: PlayerPicker,
hue: f32,
friendly_fire: bool,
}
#[derive(Debug, Serialize, Deserialize, Decode, Encode, Copy, Clone)]
@ -179,7 +180,6 @@ impl Default for AppSavedState {
player_color: PlayerColor::default(),
player_picker: PlayerPicker::None,
hue: 0.0,
friendly_fire: false
}
}
}
@ -284,7 +284,6 @@ impl App {
my_nickname,
save_state: self.run_save_state.clone(),
player_color: self.app_saved_state.player_color,
friendly_fire: self.app_saved_state.friendly_fire,
}
}
@ -563,11 +562,12 @@ impl App {
.logarithmic(true)
.text(tr("connect_settings_enemy_hp_scale")),
);
heading_with_underline(ui, tr("connect_settings_local"));
ui.add_space(20.0);
ui.checkbox(
&mut self.app_saved_state.friendly_fire,
&mut game_settings.friendly_fire,
"Friendly fire",
);
heading_with_underline(ui, tr("connect_settings_local"));
ui.checkbox(
&mut self.app_saved_state.start_game_automatically,
tr("connect_settings_autostart"),

View file

@ -98,7 +98,6 @@ pub struct NetManagerInit {
pub my_nickname: Option<String>,
pub save_state: SaveState,
pub player_color: PlayerColor,
pub friendly_fire: bool,
}
pub struct NetManager {
@ -195,7 +194,6 @@ impl NetManager {
let mut last_iter = Instant::now();
self.create_player_png(player_path.clone(),
(self.peer.my_id().unwrap().to_string(),
self.init_settings.friendly_fire,
self.init_settings.player_color));
while self.continue_running.load(atomic::Ordering::Relaxed) {
self.local_connected
@ -238,13 +236,11 @@ impl NetManager {
);
self.create_player_png(player_path.clone(),
(self.peer.my_id().unwrap().to_string(),
self.init_settings.friendly_fire,
self.init_settings.player_color));
}
state.try_ws_write(ws_encode_proxy("join", id.as_hex()));
self.send(id,
&NetMsg::Rgb((self.peer.my_id().unwrap().to_string(),
self.init_settings.friendly_fire,
self.init_settings.player_color)),
Reliability::Reliable);
}
@ -323,14 +319,13 @@ impl NetManager {
}
Ok(())
}
fn create_player_png(&self, player_path: PathBuf, rgb: (String, bool, PlayerColor)) {
fn create_player_png(&self, player_path: PathBuf, rgb: (String, PlayerColor)) {
let id = if rgb.0.len() < 5 {
format!("{:01$}", rgb.0.parse::<usize>().unwrap(), 16)
} else {
format!("{:01$X}", rgb.0.parse::<u64>().unwrap(), 16).to_ascii_lowercase()
};
let ff = rgb.1;
let rgb = rgb.2;
let rgb = rgb.1;
let tmp_path = player_path
.parent()
.unwrap();
@ -389,10 +384,11 @@ impl NetManager {
"image_file=\"mods/quant.ew/files/system/player/tmp/{}.xml\"",
id
),
format!(
/*format!(
"herd_id=\"player{}\"",
if ff {"_pvp"}else{""}
),
)*/
"herd_id=\"player\"".to_string(),
]);
Self::edit_nth_line(tmp_path
.join("unmodified_arm.xml").into(),
@ -474,6 +470,7 @@ impl NetManager {
state.try_ws_write_option("enemy_hp_scale", settings.enemy_hp_mult);
state.try_ws_write_option("world_sync_interval", settings.world_sync_interval);
state.try_ws_write_option("game_mode", settings.game_mode);
state.try_ws_write_option("friendly_fire", settings.friendly_fire);
state.try_ws_write(ws_encode_proxy("ready", ""));
// TODO? those are currently ignored by mod

View file

@ -24,7 +24,7 @@ pub enum NetMsg {
ModRaw { data: Vec<u8> },
ModCompressed { data: Vec<u8> },
WorldMessage(WorldNetMessage),
Rgb((String, bool, PlayerColor)),
Rgb((String, PlayerColor)),
}
impl From<MessageRequest<WorldNetMessage>> for MessageRequest<NetMsg> {

View file

@ -72,7 +72,7 @@ local player_fns = {
deserialize_inputs = function(message, player_data)
if (player_data ~= nil and player_data.entity ~= nil and EntityGetIsAlive(player_data.entity)) then
--print(json.stringify(message))
local controls_data = player_data.controls
local controlsComp = EntityGetFirstComponentIncludingDisabled(player_data.entity, "ControlsComponent")
@ -269,7 +269,7 @@ local player_fns = {
end
local controls = EntityGetFirstComponentIncludingDisabled(player, "ControlsComponent")
if (controls ~= nil) then
local kick = ComponentGetValue2(controls, "mButtonDownKick") -- boolean
local fire = ComponentGetValue2(controls, "mButtonDownFire") -- boolean
@ -407,10 +407,12 @@ end
function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata)
if ctx.run_ended or peer_id == ctx.my_id then
util.print_traceback()
-- TODO swap player model
end
GamePrint("Spawning player for "..peer_id)
local new = EntityLoad("mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_base.xml", x, y)
if ctx.proxy_opt.friendly_fire then
GenomeSetHerdId(new, "player_pvp")
end
local new_playerdata = existing_playerdata or player_fns.make_playerdata_for(new, peer_id)
new_playerdata.entity = new
-- util.tpcall(nickname.addLabel, new, new_playerdata.name, "data/fonts/font_pixel_white.xml", 1)
@ -511,7 +513,7 @@ function player_fns.get_current_slot(player_data)
local slot_x, slot_y = ComponentGetValue2(item_comp, "inventory_slot")
local ability_comp = EntityGetFirstComponentIncludingDisabled(held_item, "AbilityComponent")
local is_wand = false
if(ability_comp and ComponentGetValue2(ability_comp, "use_gun_script"))then
is_wand = true
@ -530,19 +532,19 @@ function player_fns.set_current_slot(slot_data, player_data)
local itemComp = EntityGetFirstComponentIncludingDisabled(item, "ItemComponent")
if itemComp ~= nil then
local item_slot_x, item_slot_y = ComponentGetValue2(itemComp, "inventory_slot")
local ability_comp = EntityGetFirstComponentIncludingDisabled(item, "AbilityComponent")
local item_is_wand = false
if(ability_comp and ComponentGetValue2(ability_comp, "use_gun_script"))then
item_is_wand = true
end
if (item_slot_x == slot_x and item_slot_y == slot_y and item_is_wand == is_wand) then
local inventory2Comp = EntityGetFirstComponentIncludingDisabled(
player_data.entity, "Inventory2Component")
local mActiveItem = ComponentGetValue2(inventory2Comp, "mActiveItem")
if (mActiveItem ~= item) then
np.SetActiveHeldEntity(player_data.entity, item, false, false)
end
@ -575,4 +577,4 @@ function player_fns.make_fire_data(special_seed, player_data)
end
end
return player_fns
return player_fns