private VanillaNonPlayer GetSelectedNPC() { RaySceneQuery raySceneQuery = this.mStateMgr.SceneMgr.CreateRayQuery(this.mStateMgr.Camera.GetCameraToViewportRay(0.5f, 0.5f)); raySceneQuery.SetSortByDistance(true); foreach (RaySceneQueryResultEntry raySQREntry in raySceneQuery.Execute()) { if (raySQREntry.movable != null) { string name = raySQREntry.movable.Name; if (!name.Contains("CharacterEnt_")) { continue; } int id = int.Parse(name.Split('_')[1]); VanillaNonPlayer npc = this.mStateMgr.MainState.CharacMgr.GetCharacterById(id) as VanillaNonPlayer; if (npc != null) { return(npc); } } } return(null); }
private bool UpdateSelectedNPC() // Return if the secondaryAction was meant to select a NPC { VanillaNonPlayer selectedCharac = this.GetSelectedNPC(); if (selectedCharac != null && selectedCharac.Info.Faction == Faction.Blue) { Console.WriteLine("Ally selected"); if (this.mSelectedAllies.Contains(selectedCharac)) { selectedCharac.SetSelected(false); this.mSelectedAllies.Remove(selectedCharac); } else { selectedCharac.SetSelected(true); this.mSelectedAllies.Add(selectedCharac); } } return(selectedCharac != null); }
public void RemoveSelectedAlly(VanillaNonPlayer charac) { this.mSelectedAllies.Remove(charac); }
public void Update(float frameTime) { MainState mainState = this.mStateMgr.MainState; VanillaPlayer mainPlayer = mainState.CharacMgr.MainPlayer; if (this.mIsMainGUIOpen && this.mTimeSinceGUIOpen.Milliseconds >= 3500 && this.mStateMgr.GameInfo.IsInEditorMode) { this.mIsMainGUIOpen = false; GUI.Visible = false; } if (this.mStateMgr.Controller.HasActionOccured(UserAction.Start)) { if (!GUI.Visible) { this.mStateMgr.MainState.OpenMainGUI(); this.SwitchGUIVisibility(true); this.mIsMainGUIOpen = true; this.mTimeSinceGUIOpen.Reset(); } else { if (this.mIsInventoryOpen) { this.SwitchInventory(false); this.mIsInventoryOpen = false; } else if (this.mIsBuilderOpen) { this.mIsBuilderOpen = false; if (this.BuildingMgr.HasActualBuilding() && !this.BuildingMgr.GetActualBuilding().Built) { this.BuildingMgr.GetActualBuilding().WaitForRessources(); } } else { this.mIsMainGUIOpen = false; /*if (this.mStateMgr.GameInfo.IsInEditorMode) * (this.mStateMgr.MainState as StoryEditorState).OnExit();*/ } this.SwitchGUIVisibility(false); GUI.Visible = false; } } if (RequestBuilderClose && this.mIsBuilderOpen) { RequestBuilderClose = false; this.mIsBuilderOpen = false; this.SwitchGUIVisibility(false); GUI.Visible = false; } if (!this.mStateMgr.Controller.IsActionOccuring(UserAction.MainAction)) { if (this.mStateMgr.Controller.HasActionOccured(UserAction.Inventory) && (!GUI.Visible || this.mIsInventoryOpen)) { this.mIsInventoryOpen = !this.mIsInventoryOpen; this.SwitchInventory(this.mIsInventoryOpen); this.SwitchGUIVisibility(this.mIsInventoryOpen); } } if (OpenBuilder) { Builder.OnOpen = this.OnBuilderOpen; new Builder(this.BuildingMgr); OpenBuilder = false; this.mIsBuilderOpen = true; this.SwitchGUIVisibility(true); } if (this.mStateMgr.Controller.HasActionOccured(UserAction.CreateUnit)) { this.PlayerRTS.CreateRobot(1); } if (this.mStateMgr.Controller.HasActionOccured(UserAction.SelectAll)) { this.mAreAllCharacSelected = !this.mAreAllCharacSelected; foreach (VanillaNonPlayer charac in this.mStateMgr.MainState.CharacMgr.GetFactionCharacters(Faction.Blue).OfType <VanillaNonPlayer>()) { if (!charac.IsFriendlySelected() && this.mAreAllCharacSelected) { this.mSelectedAllies.Add(charac); } else if (charac.IsFriendlySelected() && !this.mAreAllCharacSelected) { this.mSelectedAllies.Remove(charac); } charac.SetSelected(this.mAreAllCharacSelected); } } if (this.mStateMgr.Controller.HasActionOccured(UserAction.GoTo)) { int nbAllies = this.mSelectedAllies.Count; if (nbAllies <= 0) { return; } VanillaNonPlayer npc = this.GetSelectedNPC(); if (npc != null && npc.Info.Faction == Faction.Red) { foreach (VanillaNonPlayer ally in this.mSelectedAllies) { ally.SetTargetAndFollow(npc); } } else if (this.SelectedBlockPos != Vector3.ZERO) { int randomMax = (int)((nbAllies / 4f + 0.5f) * Cst.CUBE_SIDE); Vector3 imprecision = nbAllies == 1 ? Vector3.ZERO : new Vector3(this.mRandom.Next(0, randomMax), 0, this.mRandom.Next(0, randomMax)); foreach (VanillaNonPlayer ally in this.mSelectedAllies) { ally.MoveTo((this.SelectedBlockPos + new Vector3(0.5f, 1, -0.5f)) * Cst.CUBE_SIDE + imprecision); } } } if (this.mStateMgr.Controller.HasActionOccured(UserAction.FollowMe)) { foreach (VanillaNonPlayer ally in this.mSelectedAllies) { if (ally.IsFollowingCharac(mainPlayer)) { ally.StopFollowing(); } else { ally.Follow(mainPlayer, Cst.CUBE_SIDE * 2 + this.mRandom.Next(0, 100)); } } } /* Move camera */ if (this.IsAllowedToMoveCam) { bool secondaryActionHandled = false; if (this.IsFreeCamMode) { this.mCameraMan.UpdateCamera(frameTime, this.mStateMgr.Controller); } else if (mainPlayer.MovementInfo.IsAllowedToMove) // Just pitch the camera { this.mCamPitchNode.Pitch(new Degree(this.mStateMgr.Controller.Pitch)); if (2 * new Degree(Math.ACos(this.mCamPitchNode.Orientation.w)).ValueAngleUnits > 90.0f) // Limit the pitch between -90 degrees and +90 degrees { this.mCamPitchNode.SetOrientation(Math.Sqrt(0.5f), Math.Sqrt(0.5f) * Math.Sign(this.mCamPitchNode.Orientation.x), 0, 0); } if (this.mStateMgr.Controller.HasActionOccured(UserAction.SecondaryAction)) { secondaryActionHandled = this.UpdateSelectedNPC(); } } /* Cube addition and suppression */ float dist = this.UpdateSelectedBlock(); if (!(this.mStateMgr.GameInfo.IsInEditorMode ^ mainState.User.IsFreeCamMode) && this.SelectedBlock != null) // Allow world edition { if (this.mStateMgr.Controller.HasActionOccured(UserAction.MainAction) && !Selector.IsBullet && this.mWorld.onLeftClick(this.SelectedBlockPos)) { this.AddBlock(dist); } if (!secondaryActionHandled && this.mStateMgr.Controller.HasActionOccured(UserAction.SecondaryAction) && this.mWorld.onRightClick(this.SelectedBlockPos)) { this.DeleteBlock(); } } } /* Move Selector */ int selectorPos = Selector.SelectorPos; if (this.mStateMgr.Controller.HasActionOccured(UserAction.MoveSelectorLeft)) { selectorPos--; } if (this.mStateMgr.Controller.HasActionOccured(UserAction.MoveSelectorRight)) { selectorPos++; } for (int i = 0; i < this.mFigures.Length; i++) { if (this.mStateMgr.Controller.WasKeyPressed(this.mFigures[i])) { selectorPos = i; break; } } if (Selector.SelectorPos != selectorPos) { Selector.SelectorPos = selectorPos; } }