Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NUM_PLAYERS = 6
- if not ProfileSynchronizer_reserve_profile then
- ProfileSynchronizer_reserve_profile = ProfileSynchronizer.reserve_profile
- ProfileSynchronizer.reserve_profile = function (self, profile_index, peer_id, local_player_id)
- writelog("reserve_profile")
- return
- end
- end
- if not ProfileSynchronizer_unreserve_profile then
- ProfileSynchronizer_unreserve_profile = ProfileSynchronizer.unreserve_profile
- ProfileSynchronizer.unreserve_profile = function (self, profile_index, peer_id, local_player_id)
- writelog("unreserve_profile")
- return
- end
- end
- -- if not ProfileSynchronizer_get_first_free_profile then
- -- ProfileSynchronizer_get_first_free_profile = ProfileSynchronizer.get_first_free_profile
- -- ProfileSynchronizer.get_first_free_profile = function (self)
- --
- -- writelog("get_first_free_profile")
- --
- -- -- return ProfilePriority[1]
- -- return 3
- -- end
- -- end
- -- if not SpawnManager__update_bot_spawns then
- -- SpawnManager__update_bot_spawns = SpawnManager._update_bot_spawns
- -- SpawnManager._update_bot_spawns = function (self, dt, t)
- --
- -- -- self._available_profile_order = {4,4,4,4,4}
- -- -- SpawnManager._available_profile_order = {4,4,4,4,4}
- --
- -- return SpawnManager__update_bot_spawns(self, dt, t)
- -- end
- -- end
- if not SpawnManager__update_available_profiles then
- SpawnManager__update_available_profiles = SpawnManager._update_available_profiles
- SpawnManager._update_available_profiles = function (self, profile_synchronizer, available_profile_order, available_profiles)
- local delta = 0
- local bots = 0
- local humans = 0
- available_profiles[1] = true
- available_profiles[2] = true
- available_profiles[3] = true
- available_profiles[4] = true
- available_profiles[5] = true
- -- this is the modified line (1=WH, 2=BW, 3=DR, 4=WE, 5=ES).
- for _,profile_index in ipairs({3,3,3,3,3}) do
- table.insert(available_profile_order, 1, profile_index)
- available_profiles[profile_index] = true
- -- --for _,profile_index in ipairs({3,1,2,4,5}) do
- -- local owner_type = profile_synchronizer.owner_type(profile_synchronizer, profile_index)
- --
- -- if owner_type == "human" then
- -- table.insert(available_profile_order, 1, profile_index)
- -- available_profiles[profile_index] = true
- -- -- humans = humans + 1
- -- -- local index = table.find(available_profile_order, profile_index)
- -- --
- -- -- if index then
- -- -- table.remove(available_profile_order, index)
- -- --
- -- -- available_profiles[profile_index] = false
- -- -- delta = delta - 1
- -- -- end
- -- -- elseif (owner_type == "available" or owner_type == "bot") and not table.contains(available_profile_order, profile_index) then
- -- elseif (owner_type == "available" or owner_type == "bot") then
- -- table.insert(available_profile_order, 1, profile_index)
- --
- -- available_profiles[profile_index] = true
- -- delta = delta + 1
- -- end
- --
- -- if owner_type == "bot" then
- -- bots = bots + 1
- -- end
- end
- -- if self._forced_bot_profile_index then
- -- local forced_bot_profile_index = self._forced_bot_profile_index
- -- local index = table.find(available_profile_order, forced_bot_profile_index)
- -- local available = (index and profile_synchronizer.owner_type(profile_synchronizer, forced_bot_profile_index) == "available") or false
- --
- -- fassert(available, "Bot profile (%s) is not available!", SPProfilesAbbreviation[forced_bot_profile_index])
- --
- -- if index ~= 1 then
- -- available_profile_order[index] = available_profile_order[1]
- -- available_profile_order[1] = available_profile_order[index]
- -- end
- -- end
- return 2, 1, 3
- end
- end
- if not ProfileSynchronizer_owner_type then
- ProfileSynchronizer_owner_type = ProfileSynchronizer.owner_type
- ProfileSynchronizer.owner_type = function (self, profile_index)
- writelog("owner type")
- -- return "available"
- if self._reserved_profiles[profile_index] then
- return "human", "reserved"
- end
- local owner_table = self._profile_owners[profile_index]
- if owner_table and self.is_human_player(self, owner_table.peer_id, owner_table.local_player_id) then
- return "human"
- elseif owner_table then
- return "bot"
- else
- return "available"
- end
- return
- end
- end
- if not ProfileSynchronizer_set_profile_peer_id then
- ProfileSynchronizer_set_profile_peer_id = ProfileSynchronizer.set_profile_peer_id
- ProfileSynchronizer.set_profile_peer_id = function (self, profile_index, peer_id, local_player_id)
- writelog("set_profile_peer_id")
- -- profile_index = 4
- -- if local_player_id == nil then
- -- return
- -- end
- if local_player_id ~= nil and local_player_id > 1 then
- profile_index = 3
- end
- return ProfileSynchronizer_set_profile_peer_id(self, profile_index, peer_id, local_player_id)
- end
- end
- if not SpawnManager__assign_status_slot then
- local out = assert(io.open("profileSyncLog.txt", "w"))
- out:close()
- SpawnManager.in_inn = true
- SpawnManager.next_slot_index = 0
- SpawnManager.num_bots_ = 0
- SpawnManager.assigned_slots = {}
- SpawnManager__assign_status_slot = SpawnManager._assign_status_slot
- SpawnManager._assign_status_slot = function (self, peer_id, local_player_id, profile_index)
- writelog("SpawnManager__assign_status_slot")
- writelog("peer_id: "..tostring(peer_id).." l_p_id: "..tostring(local_player_id).." with profile_index "..tostring(profile_index))
- local NUM_PLAYERS = 6
- local latest_slot = nil
- local latest_time = -math.huge
- local first_empty, slot_index = nil
- local found_slot = false
- -- if Managers.state.game_mode ~= nil and Managers.state.game_mode._game_mode_key ~= "inn" and SpawnManager.in_inn then
- -- writelog("OUT OF INN")
- -- SpawnManager.in_inn = false
- -- SpawnManager.next_slot_index = 0
- -- end
- -- if Managers.state.game_mode ~= nil and Managers.state.game_mode._game_mode_key == "inn" and not SpawnManager.in_inn then
- -- writelog("INTO INNw")
- -- SpawnManager.in_inn = true
- -- SpawnManager.next_slot_index = 0
- -- end
- writelog("---------------CURRENT STATUS------------------")
- for i = 1, NUM_PLAYERS, 1 do
- local status = self._player_statuses[i]
- writelog("STATUS: "..tostring(status.peer_id).." "..tostring(status.local_player_id))
- end
- writelog("------------------------------------")
- for i = 1, NUM_PLAYERS, 1 do
- local status = self._player_statuses[i]
- -- writelog("STATUS: "..tostring(status.peer_id).." "..tostring(status.local_player_id))
- if status.peer_id == peer_id and status.local_player_id == local_player_id then
- status.profile_index = profile_index
- -- status.profile_index = 3
- found_slot = true
- writelog("--------------FOUND SLOT------------")
- -- slot_index = i
- -- self._take_status_slot(self, SpawnManager.next_slot_index, peer_id, local_player_id, profile_index)
- -- status.profile_index = SpawnManager.assigned_slots[peer_id..local_player_id]
- slot_index = SpawnManager.assigned_slots[peer_id..local_player_id]
- -- self._take_status_slot(self,SpawnManager.next_slot_index, peer_id, local_player_id, profile_index)
- -- SpawnManager:_take_status_slot(SpawnManager.next_slot_index, peer_id, local_player_id, profile_index)
- break
- end
- end
- if not found_slot then
- SpawnManager.next_slot_index = SpawnManager.next_slot_index+1
- if SpawnManager.next_slot_index < NUM_PLAYERS+1 then
- writelog("SpawnManager__assign_status_slot: assigning slot_index "..SpawnManager.next_slot_index.." to "..peer_id..local_player_id)
- self._take_status_slot(self,SpawnManager.next_slot_index, peer_id, local_player_id, profile_index)
- -- self._take_status_slot(self,SpawnManager.next_slot_index, peer_id, local_player_id, 3)
- slot_index = SpawnManager.next_slot_index
- SpawnManager.assigned_slots[peer_id..local_player_id] = slot_index
- end
- end
- writelog("---------------NEW STATUS------------------")
- for i = 1, NUM_PLAYERS, 1 do
- local status = self._player_statuses[i]
- writelog("STATUS: "..tostring(status.peer_id).." "..tostring(status.local_player_id))
- end
- writelog("------------------------------------")
- -- if not found_slot then
- -- self._take_status_slot(self, SpawnManager.next_slot_index+1, peer_id, local_player_id, profile_index)
- -- slot_index = SpawnManager.next_slot_index+1
- -- -- for i = 1, NUM_PLAYERS, 1 do
- -- -- local status = self._player_statuses[i]
- -- -- local last_update = status.last_update
- -- --
- -- -- if status.profile_index == profile_index then
- -- -- -- fassert(not status.peer_id, "Trying to take slot for profile already in use. old player: %q:%q, new player: %q:%q", status.peer_id, status.local_player_id, peer_id, local_player_id)
- -- -- -- self._take_status_slot(self, i, peer_id, local_player_id, profile_index)
- -- -- self._take_status_slot(self, SpawnManager.next_slot_index+1, peer_id, local_player_id, profile_index)
- -- --
- -- -- slot_index = i
- -- -- found_slot = true
- -- --
- -- -- break
- -- -- elseif not first_empty and not status.profile_index then
- -- -- first_empty = i
- -- -- end
- -- --
- -- -- if not status.peer_id and latest_time < last_update then
- -- -- latest_time = last_update
- -- -- latest_slot = i
- -- -- end
- -- -- end
- -- end
- --
- -- if not found_slot then
- -- if latest_slot then
- -- self._take_status_slot(self, SpawnManager.next_slot_index+1, peer_id, local_player_id, profile_index)
- --
- -- slot_index = SpawnManager.next_slot_index+1
- -- elseif first_empty then
- -- self._take_status_slot(self, SpawnManager.next_slot_index+1, peer_id, local_player_id, profile_index)
- --
- -- slot_index = SpawnManager.next_slot_index+1
- -- end
- -- end
- --
- -- if not slot_index then
- -- table.dump(self._player_statuses, "", 3)
- -- end
- assert(slot_index, "Did not find status slot index.")
- local cutscene_system = Managers.state.entity:system("cutscene_system")
- local first_spawn = not cutscene_system.has_intro_cutscene_finished_playing(cutscene_system)
- return first_spawn, slot_index
- end
- end
- -- if not MatchmakingManager_update then
- -- MatchmakingManager_update = MatchmakingManager.update
- -- MatchmakingManager.update = function (self, dt, t)
- -- -- Call orginal function
- -- MatchmakingManager_update(self, dt, t)
- --
- -- -- Call modded function
- -- -- if Managers.state.game_mode ~= nil and Managers.state.game_mode._game_mode_key ~= "inn" and SpawnManager.in_inn then
- -- -- writelog("OUT OF INN")
- -- -- SpawnManager.in_inn = false
- -- -- SpawnManager.next_slot_index = 0
- -- -- end
- -- -- if Managers.state.game_mode ~= nil and Managers.state.game_mode._game_mode_key == "inn" and not SpawnManager.in_inn then
- -- -- writelog("INTO INNw")
- -- -- SpawnManager.in_inn = true
- -- -- SpawnManager.next_slot_index = 0
- -- -- end
- --
- -- return
- -- end
- -- end
- -- if not SpawnManager__take_status_slot then
- -- SpawnManager__take_status_slot = SpawnManager._take_status_slot
- -- SpawnManager._take_status_slot = function (self, i, peer_id, local_player_id, profile_index)
- --
- -- -- if SpawnManager._player_statuses == nil then
- -- -- SpawnManager._player_statuses = SpawnManager._default_player_statuses(self)
- -- -- end
- -- --
- -- local status = self._player_statuses[i]
- -- --
- -- -- if status == nil then
- -- -- local settings = Managers.state.difficulty:get_difficulty_settings()
- -- --
- -- -- local CONSUMABLE_SLOTS = {
- -- -- "slot_healthkit",
- -- -- "slot_potion",
- -- -- "slot_grenade"
- -- -- }
- -- --
- -- -- status = {
- -- -- damage = 0,
- -- -- spawn_state = "not_spawned",
- -- -- health_state = "alive",
- -- -- last_update = -math.huge,
- -- -- consumables = {},
- -- -- ammo = {
- -- -- slot_ranged = 1,
- -- -- slot_melee = 1
- -- -- }
- -- -- }
- -- -- local consumables = status.consumables
- -- --
- -- -- for _, slot_name in ipairs(CONSUMABLE_SLOTS) do
- -- -- consumables[slot_name] = settings[slot_name]
- -- -- end
- -- -- end
- --
- -- -- local old_peer_id = status.peer_id
- -- -- local old_local_player_id = status.local_player_id
- --
- -- -- fassert(not old_peer_id and not old_local_player_id, "Trying to take slot that already belongs to %q %q", old_peer_id, old_local_player_id)
- --
- -- status.peer_id = peer_id
- -- status.local_player_id = local_player_id
- -- status.profile_index = profile_index
- -- status.last_update = 0
- --
- -- if status.health_state == "disabled" then
- -- status.health_state = "knocked_down"
- -- status.damage = 0
- -- end
- --
- -- -- SpawnManager._player_statuses[i] = status
- --
- -- return
- -- end
- -- end
- function writelog(line)
- local out = assert(io.open("profileSyncLog.txt", "a+"))
- -- EchoConsole(tostring(speaker)..": "..tostring(text))
- local now = os.date("*t")
- out:write(tostring(now["hour"])..":"..tostring(now["min"]).." "..tostring(line).."\n")
- out:close()
- end
- if not SpawnManager__update_bot_spawns then
- SpawnManager__update_bot_spawns = SpawnManager._update_bot_spawns
- SpawnManager._update_bot_spawns = function (self, dt, t)
- -- writelog("-- calling SpawnManager._update_bot_spawns")
- local NUM_PLAYERS = 6
- local player_manager = Managers.player
- local profile_synchronizer = self._profile_synchronizer
- local available_profile_order = self._available_profile_order
- local available_profiles = self._available_profiles
- local profile_release_list = self._bot_profile_release_list
- local delta, humans, bots = self._update_available_profiles(self, profile_synchronizer, available_profile_order, available_profiles)
- for local_player_id, bot_player in pairs(self._bot_players) do
- local profile_index = bot_player.profile_index
- if not available_profiles[profile_index] then
- local peer_id = bot_player.network_id(bot_player)
- local local_player_id = bot_player.local_player_id(bot_player)
- profile_release_list[profile_index] = true
- local bot_unit = bot_player.player_unit
- if bot_unit then
- bot_player.despawn(bot_player)
- end
- local status_slot_index = bot_player.status_slot_index
- self._free_status_slot(self, status_slot_index)
- player_manager.remove_player(player_manager, peer_id, local_player_id)
- self._bot_players[local_player_id] = nil
- end
- end
- local allowed_bots = math.min(NUM_PLAYERS - humans, (not script_data.ai_bots_disabled or 0) and (script_data.cap_num_bots or NUM_PLAYERS))
- local bot_delta = allowed_bots - bots
- local local_peer_id = Network.peer_id()
- bot_delta = SpawnManager.num_bots_ - #Managers.player:bots()
- -- bot_delta = 2
- -- bot_delta = 3 - #self._bot_players
- -- writelog("num bots"..#self._bot_players)
- -- bot_delta = 3 - #self._bot_players
- if 0 < bot_delta then
- writelog("SPAWNING BOT")
- local i = 1
- local bots_spawned = 0
- while bots_spawned < bot_delta do
- -- local profile_index = available_profile_order[i]
- local profile_index = 3
- -- fassert(profile_index, "Tried to add more bots than there are profiles available")
- -- local owner_type = profile_synchronizer.owner_type(profile_synchronizer, profile_index)
- --
- -- if owner_type == "available" then
- local local_player_id = player_manager.next_available_local_player_id(player_manager, local_peer_id)
- local bot_player = player_manager.add_bot_player(player_manager, SPProfiles[profile_index].display_name, local_peer_id, "default", profile_index, local_player_id)
- local is_initial_spawn, status_slot_index = self._assign_status_slot(self, local_peer_id, local_player_id, profile_index)
- bot_player.status_slot_index = status_slot_index
- profile_synchronizer.set_profile_peer_id(profile_synchronizer, profile_index, local_peer_id, local_player_id)
- bot_player.create_game_object(bot_player)
- self._bot_players[local_player_id] = bot_player
- self._spawn_list[#self._spawn_list + 1] = bot_player
- bots_spawned = bots_spawned + 1
- -- end
- i = i + 1
- end
- elseif bot_delta < 0 then
- writelog("NOT SPAWNING BOT, bot_delta < 0")
- local bots_despawned = 0
- local i = 1
- while bots_despawned < -bot_delta do
- local profile_index = available_profile_order[i]
- fassert(profile_index, "Tried to remove more bots than there are profiles belonging to bots")
- -- local owner_type = profile_synchronizer.owner_type(profile_synchronizer, profile_index)
- --
- -- if owner_type == "bot" then
- local bot_player, bot_local_player_id = nil
- for local_player_id, player in pairs(self._bot_players) do
- if player.profile_index == profile_index then
- bot_player = player
- bot_local_player_id = local_player_id
- break
- end
- end
- fassert(bot_player, "Did not find bot player with profile_index profile_index %i", profile_index)
- profile_release_list[profile_index] = true
- local bot_unit = bot_player.player_unit
- if bot_unit then
- bot_player.despawn(bot_player)
- end
- local status_slot_index = bot_player.status_slot_index
- self._free_status_slot(self, status_slot_index)
- player_manager.remove_player(player_manager, local_peer_id, bot_local_player_id)
- self._bot_players[bot_local_player_id] = nil
- bots_despawned = bots_despawned + 1
- -- end
- i = i + 1
- end
- end
- local statuses = self._player_statuses
- if self._network_server:has_all_peers_loaded_packages() then
- for _, bot_player in ipairs(self._spawn_list) do
- local bot_local_player_id = bot_player.local_player_id(bot_player)
- local bot_peer_id = bot_player.network_id(bot_player)
- if player_manager.player(player_manager, bot_peer_id, bot_local_player_id) == bot_player then
- local status_slot_index = bot_player.status_slot_index
- local status = statuses[status_slot_index]
- local position
- local rotation
- if status.position then
- position = status.position:unbox()
- rotation = status.rotation:unbox()
- else
- local settings = Managers.state.difficulty:get_difficulty_settings()
- local status1 = {
- damage = 0,
- spawn_state = "not_spawned",
- health_state = "alive",
- last_update = -math.huge,
- consumables = {},
- ammo = {
- slot_ranged = 1,
- slot_melee = 1
- }
- }
- local consumables = status1.consumables
- local CONSUMABLE_SLOTS = {
- "slot_healthkit",
- "slot_potion",
- "slot_grenade"
- }
- for _, slot_name in ipairs(CONSUMABLE_SLOTS) do
- consumables[slot_name] = settings[slot_name]
- end
- statuses[status_slot_index] = status1
- position = statuses[1].position:unbox()
- rotation = statuses[1].rotation:unbox()
- statuses[status_slot_index].position = statuses[1].position
- statuses[status_slot_index].rotation = statuses[1].rotation
- -- statuses[status_slot_index].health_state = "respawning"
- -- statuses[status_slot_index].respawn_unit = self.respawn_handler:get_respawn_unit()
- -- statuses[status_slot_index].damage = Managers.state.difficulty:get_difficulty_settings().respawn.damage
- end
- local is_initial_spawn = false
- if status.health_state ~= "dead" and status.health_state ~= "respawn" and status.health_state ~= "respawning" then
- local consumables = status.consumables
- local ammo = status.ammo
- local CONSUMABLE_SLOTS = {
- "slot_healthkit",
- "slot_potion",
- "slot_grenade"
- }
- bot_player.spawn(bot_player, position, rotation, is_initial_spawn, ammo.slot_melee, ammo.slot_ranged, consumables[CONSUMABLE_SLOTS[1]], consumables[CONSUMABLE_SLOTS[2]], consumables[CONSUMABLE_SLOTS[3]])
- end
- status.spawn_state = "spawned"
- end
- end
- table.clear(self._spawn_list)
- end
- return
- end
- end
- ------------------UNUSED ALREADY DECLARED ABOVE-----------------------
- local inventory_map_to_network_array = nil
- local EMPTY_TABLE = {}
- local NO_PEER = "0"
- local NO_LOCAL_PLAYER_ID = 0
- local IS_LOCAL_CALL = "is_local_call"
- ----------------UNUSED ALREADY DECLARED ABOVE-----------------------
- -- if not ProfileSynchronizer_set_profile_peer_id then ------------------UNUSED ALREADY DECLARED ABOVE-----------------------
- -- ProfileSynchronizer_set_profile_peer_id = ProfileSynchronizer.set_profile_peer_id
- -- ProfileSynchronizer.set_profile_peer_id = function (self, profile_index, peer_id, local_player_id)
- -- assert(self._is_server)
- -- assert(profile_index)
- -- assert((peer_id and local_player_id) or (not peer_id and not local_player_id), "Missing local_player_id despite assigning to peer.")
- --
- -- local new_profile_index, previous_profile_index = nil
- --
- -- writelog("-- entered set_profile_peer_id --")
- --
- --
- -- if peer_id then
- --
- -- writelog("-- there is peer_id")
- --
- -- new_profile_index = profile_index
- -- previous_profile_index = self.profile_by_peer(self, peer_id, local_player_id)
- --
- -- profile_printf("[ProfileSynchronizer] set_profile_peer_id from profile %s to %s for peer id %s:%i", tostring(previous_profile_index), tostring(new_profile_index), peer_id, local_player_id)
- -- else
- --
- -- writelog("there ISNT peer_id")
- --
- -- new_profile_index = nil
- -- previous_profile_index = profile_index
- -- local previous_owner = self._profile_owners[previous_profile_index]
- -- local peer_table = self._loaded_peers[previous_owner.peer_id]
- --
- -- if peer_table then
- -- peer_table[previous_owner.local_player_id] = nil
- --
- -- if table.is_empty(peer_table) then
- -- self._loaded_peers[previous_owner.peer_id] = nil
- -- end
- --
- -- profile_printf("[ProfileSynchronizer] set_profile_peer_id %s is no longer owned by %s:%i", tostring(previous_profile_index), (previous_owner and previous_owner.peer_id) or "<none>", (previous_owner and previous_owner.local_player_id) or 0)
- -- end
- -- end
- --
- -- if previous_profile_index then
- -- local sender = nil
- --
- -- --
- -- -- previous_profile_index = 3
- -- self._profile_select_inventory(self, previous_profile_index, EMPTY_TABLE, EMPTY_TABLE, sender, local_player_id, NO_CLIENT_SYNC_ID)
- -- end
- --
- -- transmit_peer_id = peer_id or NO_PEER
- -- local transmit_local_player_id = local_player_id or NO_LOCAL_PLAYER_ID
- --
- -- self.rpc_server_mark_profile_used(self, IS_LOCAL_CALL, transmit_peer_id, transmit_local_player_id, previous_profile_index or 0, new_profile_index or 0)
- -- self._send_rpc_lobby_clients(self, "rpc_server_mark_profile_used", transmit_peer_id, transmit_local_player_id, previous_profile_index or 0, new_profile_index or 0)
- --
- -- self._all_synced = false
- --
- -- return
- -- end
- -- end
- if not InventoryPackageSynchronizer_set_inventory_list then
- InventoryPackageSynchronizer_set_inventory_list = InventoryPackageSynchronizer.set_inventory_list
- InventoryPackageSynchronizer.set_inventory_list = function (self, profile_index, inventory_list, inventory_list_first_person)
- -- profile_index = 3
- writelog("-- entered set_inventory_list --")
- local profile_data = self.packages_by_profile[profile_index]
- if profile_data == nil then
- writelog("proflie_data is nil")
- profile_data = self.packages_by_profile[3]
- else
- writelog("proflie_data is valid for ".. profile_index)
- end
- local package_map = profile_data.package_map
- -- table.clear(package_map)
- local package_map_first_person = profile_data.package_map_first_person
- -- table.clear(package_map_first_person)
- for _, package_name in ipairs(inventory_list) do
- package_map[package_name] = true
- end
- for _, package_name in ipairs(inventory_list_first_person) do
- package_map_first_person[package_name] = true
- end
- return
- end
- end
- if not PlayerBot_spawn then
- PlayerBot_spawn = PlayerBot.spawn
- PlayerBot.spawn = function (self, position, rotation, is_initial_spawn, ammo_melee, ammo_ranged, healthkit, potion, grenade)
- writelog("-- entered PlayerBot.spawn --")
- local profile_index = self.profile_index
- profile_index = 3
- local profile = SPProfiles[profile_index]
- if profile == nil then
- profile = SPProfiles[2]
- end
- if profile == nil then
- profile = SPProfiles[4]
- end
- profile = {
- character_vo = "dwarf_ranger",
- default_wielded_slot = "slot_melee",
- display_name = "dwarf_ranger",
- ingame_short_display_name = "dwarf_ranger_short",
- character_name = "lorebook_dwarf_ranger",
- ingame_display_name = "inventory_name_dwarf_ranger",
- unit_name = "dwarf_ranger",
- sound_character = "dwarf_ranger",
- equipment_slots = {
- slot_melee = ItemMasterList.dr_2h_hammer_0001,
- slot_ranged = ItemMasterList.dr_crossbow_0001,
- slot_hat = ItemMasterList.dr_helmet_0001,
- slot_healthkit = ItemMasterList.healthkit_first_aid_kit_01
- },
- room_profile = RoomProfiles.dwarf_ranger,
- base_units = {
- first_person_bot = "units/beings/player/first_person_base/chr_first_person_bot_base",
- third_person_bot = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_base",
- third_person = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_base",
- first_person = "units/beings/player/first_person_base/chr_first_person_base",
- third_person_husk = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_husk_base"
- },
- first_person_attachment = FirstPersonAttachments.dwarf_ranger,
- first_person_heights = {
- knocked_down = 0.7,
- crouch = 0.7,
- stand = 3.3
- },
- mood_settings = {}
- }
- -- fassert(profile, "[SpawnManager] Trying to spawn with profile %q that doesn't exist in %q.", profile_index, "SPProfiles")
- local nav_world = Managers.state.entity:system("ai_system"):nav_world()
- local difficulty_manager = Managers.state.difficulty
- local difficulty_settings = difficulty_manager.get_difficulty_settings(difficulty_manager)
- local player_health = difficulty_settings.max_hp
- local player_wounds = difficulty_settings.wounds
- if script_data.player_invincible then
- player_health = -1
- end
- local character_state_class_list = {
- PlayerCharacterStateDead,
- PlayerCharacterStateInteracting,
- PlayerCharacterStateJumping,
- PlayerCharacterStateClimbingLadder,
- PlayerCharacterStateLeavingLadderTop,
- PlayerCharacterStateEnterLadderTop,
- PlayerCharacterStateFalling,
- PlayerCharacterStateKnockedDown,
- PlayerCharacterStatePouncedDown,
- PlayerCharacterStateStanding,
- PlayerCharacterStateWalking,
- PlayerCharacterStateDodging,
- PlayerCharacterStateLedgeHanging,
- PlayerCharacterStateLeaveLedgeHangingPullUp,
- PlayerCharacterStateLeaveLedgeHangingFalling,
- PlayerCharacterStateCatapulted,
- PlayerCharacterStateStunned,
- PlayerCharacterStateUsingTransport,
- PlayerCharacterStateGrabbedByPackMaster,
- PlayerCharacterStateWaitingForAssistedRespawn,
- PLayerCharacterStateOverchargeExploding
- }
- local initial_inventory = self._get_initial_inventory(self, healthkit, potion, grenade)
- local extension_init_data = {
- ai_system = {
- player = self,
- bot_profile = self.bot_profile,
- nav_world = nav_world
- },
- input_system = {
- player = self
- },
- character_state_machine_system = {
- start_state = "standing",
- nav_world = nav_world,
- character_state_class_list = character_state_class_list,
- player = self
- },
- health_system = {
- health = player_health,
- player = self
- },
- status_system = {
- wounds = player_wounds,
- profile_id = profile_index,
- player = self
- },
- hit_reaction_system = {
- is_husk = false,
- hit_reaction_template = "player"
- },
- death_system = {
- death_reaction_template = "player",
- is_husk = false
- },
- inventory_system = {
- profile = profile,
- initial_inventory = initial_inventory,
- player = self,
- ammo_percent = {
- slot_melee = ammo_melee,
- slot_ranged = ammo_ranged
- }
- },
- locomotion_system = {
- player = self
- },
- camera_system = {
- player = self
- },
- dialogue_context_system = {
- profile = profile
- },
- dialogue_system = {
- faction = "player",
- wwise_voice_switch_group = "character",
- profile = profile,
- wwise_voice_switch_value = profile.character_vo
- },
- first_person_system = {
- profile = profile
- },
- ai_navigation_system = {
- nav_world = nav_world
- },
- aim_system = {
- is_husk = false,
- template = "player"
- },
- attachment_system = {
- profile = profile,
- player = self
- },
- buff_system = {
- is_husk = false
- },
- statistics_system = {
- template = "player",
- statistics_id = self.peer_id
- },
- ai_slot_system = {
- profile_index = profile_index
- }
- }
- local unit_template_name = "player_bot_unit"
- local unit_name = profile.base_units.third_person_bot
- local spawn_data = {
- unit_template_name = unit_template_name,
- unit_name = unit_name,
- extension_init_data = extension_init_data
- }
- local unit = Managers.state.spawn:spawn_unit(spawn_data, position, rotation)
- ScriptUnit.extension(unit, "attachment_system"):show_attachments(true)
- Unit.set_data(unit, "sound_character", profile.sound_character)
- Unit.create_actor(unit, "bot_collision", false)
- if GameSettingsDevelopment.use_telemetry and self.is_server then
- self._add_spawn_telemetry(self, "host")
- end
- return unit
- end
- end
- --
- -- if not BulldozerPlayer_spawn then
- -- BulldozerPlayer_spawn = BulldozerPlayer.spawn
- -- BulldozerPlayer.spawn = function (self, optional_position, optional_rotation, is_initial_spawn, ammo_melee, ammo_ranged, healthkit, potion, grenade)
- --
- -- writelog("-- entered PBulldozerPlayer.spawn --")
- --
- -- local profile_index = self.profile_index
- -- local profile = SPProfiles[profile_index]
- -- -- profile_index = 3
- -- -- local profile = SPProfiles[3]
- --
- -- -- profile = {
- -- -- character_vo = "dwarf_ranger",
- -- -- default_wielded_slot = "slot_melee",
- -- -- display_name = "dwarf_ranger",
- -- -- ingame_short_display_name = "dwarf_ranger_short",
- -- -- character_name = "lorebook_dwarf_ranger",
- -- -- ingame_display_name = "inventory_name_dwarf_ranger",
- -- -- unit_name = "dwarf_ranger",
- -- -- sound_character = "dwarf_ranger",
- -- -- equipment_slots = {
- -- -- slot_melee = ItemMasterList.dr_2h_hammer_0001,
- -- -- slot_ranged = ItemMasterList.dr_crossbow_0001,
- -- -- slot_hat = ItemMasterList.dr_helmet_0001,
- -- -- slot_healthkit = ItemMasterList.healthkit_first_aid_kit_01
- -- -- },
- -- -- room_profile = RoomProfiles.dwarf_ranger,
- -- -- base_units = {
- -- -- first_person_bot = "units/beings/player/first_person_base/chr_first_person_bot_base",
- -- -- third_person_bot = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_base",
- -- -- third_person = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_base",
- -- -- first_person = "units/beings/player/first_person_base/chr_first_person_base",
- -- -- third_person_husk = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_husk_base"
- -- -- },
- -- -- first_person_attachment = FirstPersonAttachments.dwarf_ranger,
- -- -- first_person_heights = {
- -- -- knocked_down = 0.7,
- -- -- crouch = 0.7,
- -- -- stand = 1.3
- -- -- },
- -- -- mood_settings = {}
- -- -- }
- --
- -- writelog("spawning with profile_index "..tostring(profile_index))
- -- fassert(profile, "[SpawnManager] Trying to spawn with profile %q that doesn't exist in %q.", profile_index, "SPProfiles")
- -- print(is_initial_spawn, ammo_melee, ammo_ranged, healthkit, potion, grenade)
- --
- -- local nav_world = Managers.state.entity:system("ai_system"):nav_world()
- -- local difficulty_manager = Managers.state.difficulty
- -- local difficulty_settings = difficulty_manager.get_difficulty_settings(difficulty_manager)
- -- local player_health = difficulty_settings.max_hp
- -- local player_wounds = difficulty_settings.wounds
- --
- -- if script_data.player_invincible then
- -- player_health = -1
- -- end
- --
- -- if self.spawn_position then
- -- optional_position = self.spawn_position:unbox()
- -- self.spawn_position = nil
- -- end
- --
- -- if self.spawn_rotation then
- -- optional_rotation = self.spawn_rotation:unbox()
- -- self.spawn_rotation = nil
- -- end
- --
- -- local character_state_class_list = {
- -- PlayerCharacterStateDead,
- -- PlayerCharacterStateInteracting,
- -- PlayerCharacterStateInspecting,
- -- PlayerCharacterStateJumping,
- -- PlayerCharacterStateClimbingLadder,
- -- PlayerCharacterStateLeavingLadderTop,
- -- PlayerCharacterStateEnterLadderTop,
- -- PlayerCharacterStateFalling,
- -- PlayerCharacterStateKnockedDown,
- -- PlayerCharacterStatePouncedDown,
- -- PlayerCharacterStateStanding,
- -- PlayerCharacterStateWalking,
- -- PlayerCharacterStateDodging,
- -- PlayerCharacterStateLedgeHanging,
- -- PlayerCharacterStateLeaveLedgeHangingPullUp,
- -- PlayerCharacterStateLeaveLedgeHangingFalling,
- -- PlayerCharacterStateCatapulted,
- -- PlayerCharacterStateStunned,
- -- PlayerCharacterStateHammerLeap,
- -- PlayerCharacterStateUsingTransport,
- -- PlayerCharacterStateGrabbedByPackMaster,
- -- PlayerCharacterStateWaitingForAssistedRespawn,
- -- PLayerCharacterStateOverchargeExploding
- -- }
- -- local initial_inventory = self._get_initial_inventory(self, healthkit, potion, grenade)
- -- local extension_init_data = {
- -- input_system = {
- -- player = self
- -- },
- -- character_state_machine_system = {
- -- start_state = "standing",
- -- character_state_class_list = character_state_class_list,
- -- player = self,
- -- nav_world = nav_world
- -- },
- -- health_system = {
- -- health = player_health,
- -- player = self
- -- },
- -- status_system = {
- -- wounds = player_wounds,
- -- profile_id = profile_index,
- -- player = self
- -- },
- -- hit_reaction_system = {
- -- is_husk = false,
- -- hit_reaction_template = "player"
- -- },
- -- death_system = {
- -- death_reaction_template = "player",
- -- is_husk = false
- -- },
- -- inventory_system = {
- -- profile = profile,
- -- initial_inventory = initial_inventory,
- -- player = self,
- -- ammo_percent = {
- -- slot_melee = ammo_melee,
- -- slot_ranged = ammo_ranged
- -- }
- -- },
- -- attachment_system = {
- -- profile = profile,
- -- player = self
- -- },
- -- locomotion_system = {
- -- player = self
- -- },
- -- camera_system = {
- -- player = self
- -- },
- -- first_person_system = {
- -- profile = profile
- -- },
- -- dialogue_context_system = {
- -- profile = profile
- -- },
- -- dialogue_system = {
- -- local_player = true,
- -- faction = "player",
- -- wwise_voice_switch_group = "character",
- -- profile = profile,
- -- wwise_voice_switch_value = profile.character_vo
- -- },
- -- whereabouts_system = {
- -- nav_world = nav_world
- -- },
- -- aim_system = {
- -- is_husk = false,
- -- template = "player"
- -- },
- -- buff_system = {
- -- is_husk = false
- -- },
- -- statistics_system = {
- -- template = "player",
- -- statistics_id = self.telemetry_id(self)
- -- },
- -- ai_slot_system = {
- -- profile_index = profile_index
- -- }
- -- }
- -- local unit_template_name = nil
- -- local unit_name = profile.base_units.third_person
- -- local spawn_data = {
- -- unit_template_name = unit_template_name,
- -- unit_name = unit_name,
- -- extension_init_data = extension_init_data
- -- }
- -- local spawn_manager = Managers.state.spawn
- -- local unit = spawn_manager.spawn_unit(spawn_manager, spawn_data, optional_position, optional_rotation)
- -- local player_manager = Managers.player
- --
- -- Unit.set_data(unit, "unit_name", profile.unit_name)
- --
- -- local world = spawn_manager.world
- --
- -- LevelHelper:set_flow_parameter(world, "local_player_profile_name", profile.display_name)
- -- Unit.set_data(unit, "sound_character", profile.sound_character)
- -- Unit.create_actor(unit, "human_collision", false)
- --
- -- local is_player_unit = true
- --
- -- player_manager.assign_unit_ownership(player_manager, unit, self, is_player_unit)
- -- LevelHelper:flow_event(world, "local_player_spawned")
- --
- -- if is_initial_spawn then
- -- LevelHelper:flow_event(world, "level_start_local_player_spawned")
- -- end
- --
- -- Managers.state.event:trigger("level_start_local_player_spawned")
- --
- -- if GameSettingsDevelopment.use_telemetry then
- -- local peer_type = (self.is_server and "host") or "client"
- --
- -- self._add_spawn_telemetry(self, peer_type)
- -- end
- --
- -- return unit
- -- end
- -- end
- -- if not World_spawn_unit_ then
- -- World_spawn_unit_ = World.spawn_unit
- -- World.spawn_unit = function (world, unit_name, pos, rot)
- --
- -- writelog("-- entered World.spawn_unit --")
- -- writelog("spawning "..tostring(unit_name))
- -- local unit = World_spawn_unit(world, unit_name, pos, rot)
- -- return unit
- -- -- return World_spawn_unit_(world, unit_name, pos, rot)
- -- end
- -- end
- if not SpawnManager__default_player_statuses then
- SpawnManager__default_player_statuses = SpawnManager._default_player_statuses
- SpawnManager._default_player_statuses = function (self)
- local settings = Managers.state.difficulty:get_difficulty_settings()
- local statuses = {}
- local NUM_PLAYERS = 6
- for i = 1, NUM_PLAYERS, 1 do
- local status = {
- damage = 0,
- spawn_state = "not_spawned",
- health_state = "alive",
- last_update = -math.huge,
- consumables = {},
- ammo = {
- slot_ranged = 1,
- slot_melee = 1
- }
- }
- local consumables = status.consumables
- local CONSUMABLE_SLOTS = {
- "slot_healthkit",
- "slot_potion",
- "slot_grenade"
- }
- for _, slot_name in ipairs(CONSUMABLE_SLOTS) do
- consumables[slot_name] = settings[slot_name]
- end
- statuses[i] = status
- end
- return statuses
- end
- end
- if not SpawnManager__force_update_spawn_positions then
- SpawnManager__force_update_spawn_positions = SpawnManager._force_update_spawn_positions
- SpawnManager._force_update_spawn_positions = function (self, safe_position, safe_rotation)
- local NUM_PLAYERS = 6
- return SpawnManager__force_update_spawn_positions(self, safe_position, safe_rotation)
- end
- end
- if not SpawnManager__update_respawns then
- SpawnManager__update_respawns = SpawnManager._update_respawns
- SpawnManager._update_respawns = function (self, dt, t)
- local NUM_PLAYERS = 6
- SpawnManager__update_respawns(self, dt, t)
- return
- end
- end
- if not SpawnManager_flow_callback_add_spawn_point then
- SpawnManager_flow_callback_add_spawn_point = SpawnManager.flow_callback_add_spawn_point
- SpawnManager.flow_callback_add_spawn_point = function (self, unit)
- local NUM_PLAYERS = 6
- SpawnManager_flow_callback_add_spawn_point(self, unit)
- return
- end
- end
- if not SpawnManager__update_spawning then
- SpawnManager__update_spawning = SpawnManager._update_spawning
- SpawnManager._update_spawning = function (self, dt, t)
- local NUM_PLAYERS = 6
- return SpawnManager__update_spawning(self, dt, t)
- end
- end
- if not SpawnManager__spawn_pos_rot_from_index then
- SpawnManager__spawn_pos_rot_from_index = SpawnManager._spawn_pos_rot_from_index
- SpawnManager._spawn_pos_rot_from_index = function (self, index)
- writelog("-- endered _spawn_pos_rot_from_index with index "..index)
- if(index == 5) then index = 4 end
- position, rotation = SpawnManager__spawn_pos_rot_from_index(self, index)
- return position, rotation
- end
- end
- if not ConflictDirector_get_cluster_and_loneliness then
- ConflictDirector_get_cluster_and_loneliness = ConflictDirector.get_cluster_and_loneliness
- ConflictDirector.get_cluster_and_loneliness = function (self, min_dist)
- writelog("-- endered get_cluster_and_loneliness --")
- if self._cluster_and_loneliness[min_dist] then
- local stored = self._cluster_and_loneliness[min_dist]
- return stored[1], stored[2], stored[3], stored[4]
- end
- local positions = PLAYER_POSITIONS
- writelog("PLAYER_POSITIONS has num of elements: "..tostring(#positions))
- local new_positions = {}
- for i, v in ipairs(positions) do
- table.insert(new_positions, v)
- end
- while #new_positions ~= 1 do
- table.remove(new_positions, #new_positions)
- end
- writelog("new_positions has num of elements: "..tostring(#new_positions))
- local units = PLAYER_AND_BOT_UNITS
- local cluster_utility, loneliness_index, loneliness_value = ConflictUtils.cluster_weight_and_loneliness(new_positions, min_dist or 10)
- local loneliest_player_unit = units[loneliness_index]
- local fill = FrameTable.alloc_table()
- fill[1] = cluster_utility
- fill[2] = positions[loneliness_index]
- fill[3] = loneliness_value
- fill[4] = loneliest_player_unit
- self._cluster_and_loneliness[min_dist] = fill
- return cluster_utility, positions[loneliness_index], loneliness_value, loneliest_player_unit
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement