public void PutCommand(Client player, string item) { if (player.GetData(EntityData.PLAYER_KILLED) != 0) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_is_dead); } else if (player.GetData(EntityData.PLAYER_ON_DUTY) == 0) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_on_duty); } else { PoliceControlModel policeControl; if (player.GetData(EntityData.PLAYER_FACTION) == Constants.FACTION_POLICE) { switch (item.ToLower()) { case Commands.ARG_CONE: policeControl = new PoliceControlModel(0, string.Empty, Constants.POLICE_DEPLOYABLE_CONE, player.Position, player.Rotation); policeControl.position = new Vector3(policeControl.position.X, policeControl.position.Y, policeControl.position.Z - 1.0f); policeControl.controlObject = NAPI.Object.CreateObject(Constants.POLICE_DEPLOYABLE_CONE, policeControl.position, policeControl.rotation); policeControlList.Add(policeControl); break; case Commands.ARG_BEACON: policeControl = new PoliceControlModel(0, string.Empty, Constants.POLICE_DEPLOYABLE_BEACON, player.Position, player.Rotation); policeControl.position = new Vector3(policeControl.position.X, policeControl.position.Y, policeControl.position.Z - 1.0f); policeControl.controlObject = NAPI.Object.CreateObject(Constants.POLICE_DEPLOYABLE_BEACON, policeControl.position, policeControl.rotation); policeControlList.Add(policeControl); break; case Commands.ARG_BARRIER: policeControl = new PoliceControlModel(0, string.Empty, Constants.POLICE_DEPLOYABLE_BARRIER, player.Position, player.Rotation); policeControl.position = new Vector3(policeControl.position.X, policeControl.position.Y, policeControl.position.Z - 1.0f); policeControl.controlObject = NAPI.Object.CreateObject(Constants.POLICE_DEPLOYABLE_BARRIER, policeControl.position, policeControl.rotation); policeControlList.Add(policeControl); break; case Commands.ARG_SPIKES: policeControl = new PoliceControlModel(0, string.Empty, Constants.POLICE_DEPLOYABLE_SPIKES, player.Position, player.Rotation); policeControl.position = new Vector3(policeControl.position.X, policeControl.position.Y, policeControl.position.Z - 1.0f); policeControl.controlObject = NAPI.Object.CreateObject(Constants.POLICE_DEPLOYABLE_SPIKES, policeControl.position, policeControl.rotation); policeControlList.Add(policeControl); break; default: player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_POLICE_PUT_COMMAND); break; } } else { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_police_faction); } } }
private void RemoveClosestPoliceControlItem(Client player, int hash) { // Get the closest police control item PoliceControlModel policeControl = policeControlList.Where(control => control.controlObject != null && control.controlObject.Position.DistanceTo(player.Position) < 2.0f && control.item == hash).FirstOrDefault(); if (policeControl != null) { policeControl.controlObject.Delete(); policeControl.controlObject = null; } }
public void UpdatePoliceControlNameEvent(Client player, string policeControlSource, string policeControlTarget) { if (player.GetSharedData(EntityData.PLAYER_POLICE_CONTROL) == Constants.ACTION_SAVE) { List <PoliceControlModel> copiedPoliceControlModels = new List <PoliceControlModel>(); List <PoliceControlModel> deletedPoliceControlModels = new List <PoliceControlModel>(); foreach (PoliceControlModel policeControlModel in policeControlList) { if (policeControlModel.controlObject.Exists && policeControlModel.name != policeControlTarget) { if (policeControlModel.name != string.Empty) { PoliceControlModel policeControlCopy = policeControlModel.Copy(); policeControlModel.controlObject = null; policeControlCopy.name = policeControlTarget; Task.Factory.StartNew(() => { policeControlCopy.id = Database.AddPoliceControlItem(policeControlCopy); copiedPoliceControlModels.Add(policeControlCopy); }); } else { policeControlModel.name = policeControlTarget; Task.Factory.StartNew(() => { // Add new element to the control policeControlModel.id = Database.AddPoliceControlItem(policeControlModel); }); } } } policeControlList.AddRange(copiedPoliceControlModels); } else { policeControlList.Where(s => s.name == policeControlSource).ToList().ForEach(t => t.name = policeControlTarget); Task.Factory.StartNew(() => { // Rename the control Database.RenamePoliceControl(policeControlSource, policeControlTarget); }); } }
public void PoliceControlSelectedEvent(Client player, string policeControl) { if (player.GetSharedData(EntityData.PLAYER_POLICE_CONTROL) == Constants.ACTION_LOAD) { foreach (PoliceControlModel policeControlModel in policeControlList) { if (!policeControlModel.controlObject.Exists && policeControlModel.name == policeControl) { policeControlModel.controlObject = NAPI.Object.CreateObject(policeControlModel.item, policeControlModel.position, policeControlModel.rotation); } } } else if (player.GetSharedData(EntityData.PLAYER_POLICE_CONTROL) == Constants.ACTION_SAVE) { List <PoliceControlModel> copiedPoliceControlModels = new List <PoliceControlModel>(); List <PoliceControlModel> deletedPoliceControlModels = new List <PoliceControlModel>(); foreach (PoliceControlModel policeControlModel in policeControlList) { if (policeControlModel.controlObject.Exists && policeControlModel.name != policeControl) { if (policeControlModel.name != string.Empty) { PoliceControlModel policeControlCopy = policeControlModel; policeControlCopy.name = policeControl; Task.Factory.StartNew(() => { policeControlCopy.id = Database.AddPoliceControlItem(policeControlCopy); copiedPoliceControlModels.Add(policeControlCopy); }); } else { policeControlModel.name = policeControl; Task.Factory.StartNew(() => { // Add the new element policeControlModel.id = Database.AddPoliceControlItem(policeControlModel); }); } } else if (!policeControlModel.controlObject.Exists && policeControlModel.name == policeControl) { Task.Factory.StartNew(() => { Database.DeletePoliceControlItem(policeControlModel.id); deletedPoliceControlModels.Add(policeControlModel); }); } } policeControlList.AddRange(copiedPoliceControlModels); policeControlList = policeControlList.Except(deletedPoliceControlModels).ToList(); } else { foreach (PoliceControlModel policeControlModel in policeControlList) { if (policeControlModel.controlObject.Exists && policeControlModel.name == policeControl) { policeControlModel.controlObject.Delete(); } } policeControlList.RemoveAll(control => control.name == policeControl); Task.Factory.StartNew(() => { // Delete the police control Database.DeletePoliceControl(policeControl); }); } }