private bool RequestControlInternal(EquiEntityControllerComponent controller, EquiPlayerAttachmentComponent.Slot controlled) { var desiredControlling = new ControlledId(controlled); if (_controlledToController.ContainsKey(desiredControlling)) { return(false); } ControlledId currentlyControlling; if (_controllerToControlled.TryGetValue(controller.Entity.EntityId, out currentlyControlling)) { if (currentlyControlling.Equals(controlled)) { return(true); } if (!ReleaseControlInternal(controller)) { return(false); } } return(controller.RequestControlInternal(controlled)); }
internal void Link(long controller, ControlledId key) { long existingController; if (_controlledToController.TryGetValue(key, out existingController)) { if (existingController == controller) { return; } this.GetLogger().Warning($"Controllable slot {key} is already controlled by {existingController}"); Unlink(existingController); } ControlledId existingControlled; if (_controllerToControlled.TryGetValue(controller, out existingControlled)) { if (existingControlled.Equals(key)) { return; } this.GetLogger().Warning($"Controller {controller} is already controlling {existingControlled}"); Unlink(controller); } _controlledToController.Add(key, controller); _controllerToControlled.Add(controller, key); }