public void PlaceEntity(Loc position) { GroundEntity placeableEntity = EntBrowser.CreateEntity(); if (placeableEntity == null) { return; } placeableEntity.Position = position; placeableEntity.EntName = ZoneManager.Instance.CurrentGround.FindNonConflictingName(placeableEntity.EntName); placeableEntity.SyncScriptEvents(); DiagManager.Instance.DevEditor.GroundEditor.Edits.Apply(new GroundEntityStateUndo(0)); if (placeableEntity.GetEntityType() == GroundEntity.EEntTypes.Character) { ZoneManager.Instance.CurrentGround.AddMapChar((GroundChar)placeableEntity); } else if (placeableEntity.GetEntityType() == GroundEntity.EEntTypes.Object) { ZoneManager.Instance.CurrentGround.AddObject((GroundObject)placeableEntity); } else if (placeableEntity.GetEntityType() == GroundEntity.EEntTypes.Marker) { ZoneManager.Instance.CurrentGround.AddMarker((GroundMarker)placeableEntity); } else if (placeableEntity.GetEntityType() == GroundEntity.EEntTypes.Spawner) { ZoneManager.Instance.CurrentGround.AddSpawner((GroundSpawner)placeableEntity); } }
public void RemoveEntity(GroundEntity ent) { if (ent == null) { return; } DiagManager.Instance.DevEditor.GroundEditor.Edits.Apply(new GroundEntityStateUndo(0)); if (ent.GetEntityType() == GroundEntity.EEntTypes.Character) { ZoneManager.Instance.CurrentGround.RemoveMapChar((GroundChar)ent); } else if (ent.GetEntityType() == GroundEntity.EEntTypes.Object) { ZoneManager.Instance.CurrentGround.RemoveObject((GroundObject)ent); } else if (ent.GetEntityType() == GroundEntity.EEntTypes.Marker) { ZoneManager.Instance.CurrentGround.RemoveMarker((GroundMarker)ent); } else if (ent.GetEntityType() == GroundEntity.EEntTypes.Spawner) { ZoneManager.Instance.CurrentGround.RemoveSpawner((GroundSpawner)ent); } }
//=========================================== // Methods //=========================================== /// <summary> /// Helper function to make an entity run the specified task. /// Will not replace a running task! /// Tasks are run interlocked with the script processing and game processing, and characters can run tasks at the same time. /// </summary> /// <param name="ent">Entity which will run the task.</param> /// <param name="fn">Task coroutine.</param> /// <returns>Returns whether the task could be set or not</returns> public GroundScriptedTask StartEntityTask(GroundEntity ent, LuaFunction fn) { try { if (ent == null || fn == null) { DiagManager.Instance.LogInfo(String.Format("ScriptTask.StartEntityTask(): Got null entity or function pointer!")); return(null); } if (ent.GetType().IsSubclassOf(typeof(BaseTaskUser))) { BaseTaskUser tu = (BaseTaskUser)ent; GroundScriptedTask task = new GroundScriptedTask(fn); if (tu.SetTask(task)) { return(task); } } } catch (Exception ex) { DiagManager.Instance.LogInfo(String.Format("ScriptTask.StartEntityTask(): Got exception :\n{0}", ex.Message)); } return(null); }
public YieldInstruction _MoveToPosition(GroundEntity ent, int x, int y, bool run = false, int speed = 2) { if (speed < 1) { DiagManager.Instance.LogInfo("ScriptGround.MoveToPosition(): Got invalid walk speed!"); return(null); } if (ent is GroundChar) { GroundChar ch = (GroundChar)ent; FrameTick prevTime = new FrameTick(); GroundAction prevAction = ch.GetCurrentAction(); if (prevAction is WalkToPositionGroundAction) { prevTime = prevAction.ActionTime; } WalkToPositionGroundAction newAction = new WalkToPositionGroundAction(ch.Position, ch.Direction, run, speed, prevTime, new Loc(x, y)); ch.StartAction(newAction); return(new WaitUntil(() => { return newAction.Complete; })); } else { DiagManager.Instance.LogInfo("ScriptGround.MoveToPosition(): Got invalid entity!"); } return(null); }
/// <summary> /// Make an entity immediately turn towards a direction /// </summary> /// <param name="curch"></param> /// <param name="direction"></param> public void EntTurn(GroundEntity ent, Dir8 direction) { if (ent == null || direction == Dir8.None) { return; } ent.Direction = direction; }
public void SelectEntity(GroundEntity ent) { if (ent != null) { DiagManager.Instance.DevEditor.GroundEditor.Edits.Apply(new GroundEntityStateUndo(0)); } EntBrowser.SelectEntity(ent); }
private void CategorizePosition(bool stayOnGround) { _surfaceFriction = 1.0f; var point = Pos - Vector3.Up * 2; var bumpOrigin = Pos; var movingUpRapidly = Velocity.z > MaxNonJumpVelocity; var moveToEndPos = false; if (GroundEntity != null) { moveToEndPos = true; point.z -= StepSize; } else if (stayOnGround) { moveToEndPos = true; point.z -= StepSize; } if (movingUpRapidly || Swimming) { ClearGroundEntity(); return; } var hasGroundEntity = (GroundEntity != null && GroundEntity.IsValid()); var pm = TraceBBox(bumpOrigin, point, 4.0f); if (pm.Entity == null || pm.Normal.z < GroundNormalZ) { ClearGroundEntity(); moveToEndPos = false; if (Velocity.z > 0) { _surfaceFriction = 0.25f; } } else { UpdateGroundEntity(pm); if (!hasGroundEntity && GroundEntity != null && GroundEntity.IsValid()) { OnNewGroundEntity(GroundEntity, Velocity); } } if (moveToEndPos && !pm.StartedSolid && pm.Fraction > 0.0f && pm.Fraction < 1.0f) { Pos = pm.EndPos; } OnPostCategorizePosition(stayOnGround, pm); }
public YieldInstruction _MoveToPosition(GroundEntity ent, double x, double y, bool run = false) { if (ent is GroundChar) { GroundChar ch = (GroundChar)ent; ch.StartAction(new WalkToPositionGroundAction(ch.Position, ch.Direction, run, new FrameTick(), new Loc((int)x, (int)y), () => { this.m_actionComplete = true; })); return(new WaitUntil(() => { return this.m_actionComplete; })); } return(null); }
public void Unhide(string entityname) { GroundEntity found = ZoneManager.Instance.CurrentGround.FindEntity(entityname); if (found == null) { DiagManager.Instance.LogInfo(String.Format("ScriptGround.Unhide({0}): Couldn't find entity to un-hide!", entityname)); return; } //Enable the entity found.EntEnabled = true; }
/// <summary> /// Returns skidmark material for the current texture. /// </summary> public Material GetCurrentSkidmarkTexture(WheelController wheelController) { GroundEntity groundEntity = GetCurrentGroundEntity(wheelController); if (groundEntity != null) { return(GetCurrentGroundEntity(wheelController).skidmarkMaterial); } else { return(null); } }
/// <summary> /// Gets index of current ground entity in ground entities list. /// </summary> public int GetCurrentGroundEntityIndex(WheelController wheelController) { GroundEntity groundEntity = GetCurrentGroundEntity(wheelController); if (groundEntity != null) { return(groundEntities.IndexOf(groundEntity)); } else { return(-1); } }
/// <summary> /// Helper function to force stop an entity's current task! /// </summary> /// <param name="ent">Entity running the task to stop.</param> public void StopEntityTask(GroundEntity ent) { try { if (ent.GetType().IsSubclassOf(typeof(BaseTaskUser))) { BaseTaskUser tu = (BaseTaskUser)ent; GroundTask task = tu.CurrentTask(); if (task != null) { task.ForceStop(); } } } catch (Exception ex) { DiagManager.Instance.LogInfo(String.Format("ScriptTask.StopEntityTask(): Got exception :\n{0}", ex.Message)); } }
/// <summary> /// Helper function to invoke the Wait() function of the current task of the specified entity. /// </summary> /// <param name="ent">Entity which task we'll wait on.</param> /// <returns></returns> public Coroutine _WaitEntityTask(GroundEntity ent) { try { if (ent.GetType().IsSubclassOf(typeof(BaseTaskUser))) { BaseTaskUser tu = (BaseTaskUser)ent; if (tu.CurrentTask() != null) { return(tu.CurrentTask().Wait()); } } } catch (Exception ex) { DiagManager.Instance.LogInfo(String.Format("ScriptTask._WaitEntityTask(): Got exception :\n{0}", ex.Message)); } return(new Coroutine(LuaEngine._DummyWait())); }
/// <summary> /// Same as StartEntityTask, but this one blocks until the task is set /// </summary> /// <param name="ent"></param> /// <param name="fn"></param> public Coroutine _WaitStartEntityTask(GroundEntity ent, LuaFunction fn) { try { if (ent == null || fn == null) { DiagManager.Instance.LogInfo(String.Format("ScriptTask._WaitStartEntityTask(): Got null entity or function pointer!")); } if (ent.GetType().IsSubclassOf(typeof(BaseTaskUser))) { BaseTaskUser tu = (BaseTaskUser)ent; return(new Coroutine(tu.WaitSetTask(new GroundScriptedTask(fn)))); } } catch (Exception ex) { DiagManager.Instance.LogInfo(String.Format("ScriptTask._WaitStartEntityTask(): Got exception :\n{0}", ex.Message)); } return(new Coroutine(LuaEngine._DummyWait())); }
public override void DrawDebug(SpriteBatch spriteBatch) { base.DrawDebug(spriteBatch); if (ZoneManager.Instance.CurrentGround != null) { GroundEntity selectedEntity = null; foreach (GroundEntity entity in ZoneManager.Instance.CurrentGround.IterateEntities()) { if (entity.DevEntitySelected) { selectedEntity = entity; } } if (selectedEntity != null) { GraphicsManager.SysFont.DrawText(spriteBatch, GraphicsManager.WindowWidth - 2, 62, String.Format("Obj X:{0:D3} Y:{1:D3}", selectedEntity.MapLoc.X, selectedEntity.MapLoc.Y), null, DirV.Up, DirH.Right, Color.White); } } }
public YieldInstruction _MoveToLoc(GroundEntity ent, RogueElements.Loc pos, bool run = false) { return(_MoveToPosition(ent, pos.X, pos.Y, run)); }
private void loadMap() { Debug.Log("load map"); mapLoaded = true; string map = jsonMap; populationMatrix = new List<PopulationEntity>[mapsize, mapsize]; mapMatrix = new GroundEntity[mapsize, mapsize]; map = map.Substring(1); map = map.Remove(map.Length - 3); //charactères en trop ? var mapArray = map.Split(','); int i = 0, j = 0; GameObject obj; GroundEntity ent; foreach (string s in mapArray) { int tile = int.Parse(s); switch (tile) { case 2: obj = GameObject.Instantiate(Resources.Load("sea")) as GameObject; ent = new GroundEntity(0, obj); break; case 6: default: obj = GameObject.Instantiate(Resources.Load("ground")) as GameObject; ent = new GroundEntity(1, obj); break; case 7: obj = GameObject.Instantiate(Resources.Load("grass")) as GameObject; ent = new GroundEntity(2, obj); break; } var mapNode = GameObject.FindGameObjectWithTag("Map"); obj.transform.parent = mapNode.transform; obj.transform.position = new Vector3(tilesize * i, -tilesize * j, 0); mapMatrix[i, j] = ent; populationMatrix[i, j] = new List<PopulationEntity>(); i++; if (i == mapsize) { i = 0; j++; } } Debug.Log("map loaded"); }
public YieldInstruction _MoveToMarker(GroundEntity ent, GroundMarker mark, bool run = false, int speed = 2) { return(_MoveToPosition(ent, mark.X, mark.Y, run, speed)); }
public EntScriptItem(LuaEngine.EEntLuaEventTypes eventType, GroundEntity ent) { EventType = eventType; baseEnt = ent; }