Skip to content

Commit

Permalink
Bugfix/tp2squadmate locality issues (#26)
Browse files Browse the repository at this point in the history
* renamed layout to reflect what it is

* moved to rpc from local GM to server for teleporting other players

* fixed review comments, moved static emptyTerrainAreaRadius and removed unnessecary function

* added prefix to static variable
  • Loading branch information
Crowdedlight authored Aug 13, 2023
1 parent 4f2df21 commit 42ad23a
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 33 deletions.
1 change: 0 additions & 1 deletion Configs/Editor/ActionLists/Context/TempEdit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SCR_EditorActionList {
m_iOrder 200
m_bEnableShortcutLogics 0
m_bShowOnCooldownNotification 0
m_bIsServer 1
}
}
}
4 changes: 2 additions & 2 deletions Configs/System/chimeraMenus.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MenuManager {
MenuPresets {
MenuPreset ODIN_ListBox_ID {
Layout "{73A9C9284FFE3376}UI/layouts/ODIN_ListBox.layout"
MenuPreset ODIN_Listbox_SingleSelect_ID {
Layout "{73A9C9284FFE3376}UI/layouts/ODIN_ListBox_SingleSelect.layout"
Class "ODIN_ListboxSingleSelectDialog"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//------------------------------------------------------------------------------------------------
[BaseContainerProps(), SCR_BaseContainerCustomTitleUIInfo("m_Info")]
class ODIN_TeleportToSquadmateContextAction: SCR_BaseContextAction
{
static int emptyTerrainAreaRadius = 20;

{
override bool CanBeShown(SCR_EditableEntityComponent hoveredEntity, notnull set<SCR_EditableEntityComponent> selectedEntities, vector cursorWorldPosition, int flags)
{
if (!hoveredEntity)
Expand Down Expand Up @@ -32,7 +30,7 @@ class ODIN_TeleportToSquadmateContextAction: SCR_BaseContextAction

GenericEntity owner = hoveredEntity.GetOwner();

MenuBase myMenu = GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.ODIN_ListBox_ID, DialogPriority.INFORMATIVE, 0, true);
MenuBase myMenu = GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.ODIN_Listbox_SingleSelect_ID, DialogPriority.INFORMATIVE, 0, true);

// null check
if (!myMenu)
Expand Down Expand Up @@ -105,35 +103,19 @@ class ODIN_TeleportToSquadmateContextAction: SCR_BaseContextAction
ODIN_LogHelper.Log("ChimeraCharacter in userdata for selected listbox item is null", "TeleportToSquadmateContextAction", LogLevel.WARNING);
return;
}

// If target is sitting in a vehicle, move player inside as well (Taken from SCR_PlayerSpawnPoint.c)
SCR_CompartmentAccessComponent compartmentAccessTarget = SCR_CompartmentAccessComponent.Cast(selectedPlayer.FindComponent(SCR_CompartmentAccessComponent));
IEntity vehicle = compartmentAccessTarget.GetVehicle();
if (vehicle)
{
SCR_CompartmentAccessComponent compartmentAccessPlayer = SCR_CompartmentAccessComponent.Cast(hoveredEntity.GetOwner().FindComponent(SCR_CompartmentAccessComponent));

// only return here if we were succesfull in moving into vehicle. If false its likely vehicle is full; Then we continue function to move unit right next to vehicle
if (compartmentAccessPlayer.MoveInVehicleAny(vehicle))
return;
}

// Get world coordinates of player
vector target_pos;
SCR_WorldTools.FindEmptyTerrainPosition(target_pos, selectedPlayer.GetOrigin(), emptyTerrainAreaRadius);

// get transform for rotation etc.
vector target_transform[4];
hoveredEntity.GetTransform(target_transform);

// use new position, but keep rotation
target_transform[3] = target_pos;

hoveredEntity.SetTransform(target_transform, true);
// get target player RplId
RplComponent targetRpl = RplComponent.Cast(selectedPlayer.FindComponent(RplComponent));
if (!targetRpl)
return;

// Call RPC through EditorManagerEntity to reach server
SCR_EditorManagerEntity managerEntity = SCR_EditorManagerEntity.GetInstance();
managerEntity.ODIN_TeleportEntityToPlayer(hoveredEntity.GetOwnerRplId(), targetRpl.Id());
}

override bool IsServer()
{
return true;
return false;
}
};
79 changes: 79 additions & 0 deletions Scripts/Game/ODIN/Editor/Entities/SCR_EditorManagerEntity.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/** @ingroup Editor_Entities
*/

/*!
The entity which enables all editor functionality for the player.
- It's **created by SCR_EditorManagerCore** when a player connects.
+ Every player receives one.
- In multiplayer, the entity is **local to the player**.
+ This is required to allow communication with server (see Replication for more details).
+ Requires RplComonent to function.
- This entity handles **only barebone editor functionality**, like access rules, or opening and closing.
- Everything else, like camera or menu handling, must be on specialized editor modes (SCR_EditorModeEntity) and components (SCR_BaseEditorComponent)!
- Editor can have a limitied state, influenced by its modes and checked by IsLimited() function:
+ Editor is **limited** if all its modes are.
+ If at least one mode is unlimited, the editor is **unlimited** as well.
+ The state influences behavior of certain components, e.g., photo mode camera movement may be restricted if the editor is limited.
+ As a rule of thumb, unlimited state means that player can ***cheat*** with the editor.
- Default editor manager prefab is defined in SCR_EditorManagerCore (config is Configs/Core folder).
*/
modded class SCR_EditorManagerEntity : SCR_EditorBaseEntity
{
static int ODIN_emptyTerrainAreaRadius = 20;

/*!
Functions to tell the server to move an entity
*/
void ODIN_TeleportEntityToPlayer(RplId sourceEntityId, RplId targetEntityId)
{
Rpc(ODIN_Server_TeleportEntityToPlayer, sourceEntityId, targetEntityId);
}

[RplRpc(RplChannel.Reliable, RplRcver.Server)]
protected void ODIN_Server_TeleportEntityToPlayer(RplId entityId, RplId targetEntityId)
{
// get entity from id
RplComponent entityRpl = RplComponent.Cast(Replication.FindItem(entityId));
RplComponent targetRpl = RplComponent.Cast(Replication.FindItem(targetEntityId));

if (!entityRpl || !targetRpl)
return;

IEntity sourceEntity = entityRpl.GetEntity();
IEntity targetEntity = targetRpl.GetEntity();

if (!sourceEntity || !targetEntity)
return;

// If target is sitting in a vehicle, move player inside as well (Taken from SCR_PlayerSpawnPoint.c)
SCR_CompartmentAccessComponent compartmentAccessTarget = SCR_CompartmentAccessComponent.Cast(targetEntity.FindComponent(SCR_CompartmentAccessComponent));
IEntity vehicle = compartmentAccessTarget.GetVehicle();
if (vehicle)
{
SCR_CompartmentAccessComponent compartmentAccessPlayer = SCR_CompartmentAccessComponent.Cast(sourceEntity.FindComponent(SCR_CompartmentAccessComponent));

// if we succeed, we return to avoid teleporting the unit after having moved him into the vehicle. If we fail, we just continue and TP player next to vehicle
if (compartmentAccessPlayer.MoveInVehicleAny(vehicle))
return;
}

// Get world coordinates of player
vector target_pos;
SCR_WorldTools.FindEmptyTerrainPosition(target_pos, targetEntity.GetOrigin(), ODIN_emptyTerrainAreaRadius);

// get transform for rotation etc.
vector target_transform[4];
sourceEntity.GetTransform(target_transform);

// use new position, but keep rotation
target_transform[3] = target_pos;

// Get editable component
SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(sourceEntity.FindComponent(SCR_EditableEntityComponent));

// call transform
if (editableEntity)
editableEntity.SetTransform(target_transform, true);
}
};
2 changes: 1 addition & 1 deletion Scripts/Game/ODIN/UI/Menu/ChimeraMenuBase.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
//! Menu presets
modded enum ChimeraMenuPreset
{
ODIN_ListBox_ID,
ODIN_Listbox_SingleSelect_ID,
};
File renamed without changes.
File renamed without changes.

0 comments on commit 42ad23a

Please sign in to comment.