public static JobComponent ScheduleJobControllerInWorld( WorldComponent worldComponent, Job job) { GameObject entityObject = new GameObject(); JobComponent entityComponent = entityObject.AddComponent <JobComponent>(); entityObject.transform.SetParent(worldComponent.transform); IndicatorBar bar = IndicatorBar.Instantiate(entityObject); bar.GetSizeCallback = new IndicatorBar.GetSize( () => { return(job.CurrentStage().CurrentProgress()); } ); entityObject.name = job.id + "_indicator"; entityComponent.job = job; PolygonCollider2D collider = entityObject.AddComponent <PolygonCollider2D>(); collider.points = new Vector2[] { new Vector2(-0.5f, -0.5f), new Vector2(-0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, -0.5f) }; entityComponent.spriteRenderer = entityObject.AddComponent <SpriteRenderer>(); entityComponent.spriteRenderer.sprite = SpriteLoader.GetSprite("test"); return(entityComponent); }
public void BlockChange(Player p, BlockChangeEventArgs args) { p.OnPlayerBlockChange.Normal -= BlockChange; WorldComponent.GenerateTree(p, args.X, args.Z, args.Y, (TreeType)p.ExtraData["TreeType"], ServerSettings.GetSettingBoolean("TreesGoThrough")); args.Cancel(); p.ExtraData.Remove("TreeType"); }
public void Run() { WorldComponent world = _world.Components1[0]; foreach (int i in _stoppedGhosts) { int ghostEntity = _stoppedGhosts.Entities[i]; _ecsWorld .AddComponent <ChangeDirectionComponent>(ghostEntity) .NewDirection = Random.NextEnum <Directions>(); } foreach (int i in _ghosts) { Vector2Int currentPosition = _ghosts.Components1[i].Position; foreach (int entity in world.WorldField[currentPosition.x][currentPosition.y]) { var player = _ecsWorld.GetComponent <PlayerComponent>(entity); var isDead = _ecsWorld.GetComponent <PlayerIsDeadEvent>(entity); if (player != null && isDead == null) { _ecsWorld.AddComponent <PlayerIsDeadEvent>(entity); } } } }
/// <summary> /// Returns a populated world grid for testing. /// </summary> /// <returns></returns> private WorldGrid GetPopulatedWorldGrid() { WorldGrid grid = new WorldGrid(800, 800, 200, 200); // Populate float[] posX = new float[] { 250, 450, 650, 750, 210, 450, 500, 50, 250, 750 }; float[] posY = new float[] { 50, 50, 50, 150, 300, 300, 500, 700, 700, 700 }; for (int i = 0; i < posX.Length; i++) { WorldComponent comp = new WorldComponent(); comp.Entity = new Entity(i); comp.PositionComponent = new PositionComponent(); comp.PositionComponent.Position = new Vector2(posX[i], posY[i]); grid.Add(comp); } return(grid); }
private EnemyHealth GetClosest() { var stacks = COMPONENT_DATABASE.RetrieveComponents <EnemyHealth>(); if (stacks.Count == 0) { return(null); } WorldComponent closest = null; float closestDist = float.MaxValue; foreach (var stack in stacks) { float dist = (stack.gameObject.transform.position - transform.position).magnitude; if (dist < closestDist) { closest = stack; closestDist = dist; } } return((EnemyHealth)closest); }
public OctoGame() : base() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; this.Window.Title = "OctoAwesome"; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; this.IsMouseVisible = true; input = new InputComponent(this); input.UpdateOrder = 1; Components.Add(input); world = new WorldComponent(this, input); world.UpdateOrder = 2; Components.Add(world); //camera = new CameraComponent(this, world, input); //camera.UpdateOrder = 3; //Components.Add(camera); camera3d = new Camera3DComponent(this, world); camera3d.UpdateOrder = 3; Components.Add(camera3d); render3d = new Render3DComponent(this, world, camera3d); render3d.DrawOrder = 1; Components.Add(render3d); }
private static bool GetManagerForPrefix(Pawn pawn, bool createIfMissing, WorldComponent __instance, ref object __result) { if (MP.IsInMultiplayer || !createIfMissing) { return(true); // We don't care and let the method run, we only care if we might need to creat a VerbManager } var table = mvcfManagersTableField.GetValue(__instance); var parameters = new object[] { pawn, null }; if ((bool)conditionalWeakTableTryGetValueMethod.Invoke(table, parameters)) { // Might as well give the result back instead of continuing the normal execution of the method, // as it would just do the same stuff as we do here again __result = parameters[1]; } else { // We basically setup an empty reference, but we'll initialize it in the synced method. // We just return the reference for it so other objects can use it now. The data they // have will be updated after the sync, so the gizmos related to verbs might not be // shown immediately for players who selected specific pawns. __result = CreateAndAddVerbManagerToCollections(pawn, __instance, table: table); } // Ensure VerbManager is initialized for all players, as it might not be SyncedInitVerbManager(pawn); return(false); }
private void Body_OnCollision(Fixture fixtureA, Fixture fixtureB, VelcroPhysics.Collision.ContactSystem.Contact contact) { WorldComponent ground = (fixtureB.Body.UserData as WorldComponent); if (ground != null) { RectangleFloat bounds = ground.Bounds; RectangleFloat heroBounds = Platman.Bounds; var bottom = Math.Abs(heroBounds.Bottom - bounds.Top); var top = Math.Abs(heroBounds.Top - bounds.Bottom); var left = Math.Abs(heroBounds.Left - bounds.Right); var right = Math.Abs(heroBounds.Right - bounds.Left); float[] values = new float[] { bottom, top, left, right }; Array.Sort(values); float edge = values[0]; bool b = false; if (World.Gravity == VelocityValues.Instance.GravityDown) { if (heroBounds.Bottom <= bounds.Top && bottom == edge) { b = true; } } else if (World.Gravity == VelocityValues.Instance.GravityUp) { if (heroBounds.Top > bounds.Bottom && top == edge) { b = true; } } else if (World.Gravity == VelocityValues.Instance.GravityRight) { if (heroBounds.Right <= bounds.Left && right == edge) { b = true; } } else if (World.Gravity == VelocityValues.Instance.GravityLeft) { if (heroBounds.Left > bounds.Right && left == edge) { b = true; } } if (b) { isOverGround = true; overGround = ground; ApplyFallColisionImpulse(); } } }
public BlueprintDamage(BlueprintDamageType type, short tileX, short tileY, sbyte level, WorldComponent component) { this.Type = type; this.TileX = tileX; this.TileY = tileY; this.Level = level; this.Component = component; }
private void Body_OnSeparation(Fixture fixtureA, Fixture fixtureB, VelcroPhysics.Collision.ContactSystem.Contact contact) { WorldComponent ground = (fixtureB.Body.UserData as WorldComponent); if (overGround == ground) { isOverGround = false; } }
public static Viewport GetCurrentViewport(GraphicsDevice graphicsDevice) { ComponentManager cm = ComponentManager.GetInstance(); WorldComponent world = (from w in cm.GetComponentsOfType <WorldComponent>().Values select w).First() as WorldComponent; Rectangle bounds = new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height); bounds.Offset(world.Center - new Point(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height / 2)); return(new Viewport(bounds)); }
public Player() { _spritePoint = Point.Zero; //Position = Vector2.Zero; Position = new Vector2(16 * 16, 8 * 16); _world = ComponentManager.Instance.GetInstance <WorldComponent>(); RegisterEvents(); _animation = new IdleAnimation(); }
// PRIVATE MODIFIERS private void UpdateListenArea() { Collider2D[] col = Physics2D.OverlapCircleAll(transform.position, god.max_radius * listen_percent); //Debug.Log(col.Length); for (int i = 0; i < col.Length; ++i) { WorldComponent wc = col[i].gameObject.GetComponent <WorldComponent>(); if (wc != null) { wc.TurnOn(); } } }
public void Initialize() { worldEntity = _world.CreateEntityWith <WorldComponent>(); worldEntity.Width = 320; worldEntity.Height = 240; LoadMap(Resources.Birb); var ballEntity = MakeBall(); BuildWalls(); BuildPaddle(); }
public override float GetScore(Tile tile, int tileID) { // return 0f; if (!AlphaBiomes_Settings.AB_SpawnTarPits) { return(-100f); } if (tile.WaterCovered) { return(-100f); } if (tile.hilliness != Hilliness.Flat) { return(-100f); } if (tile.temperature < 0f) { return(0f); } if (tile.rainfall < 100f || tile.rainfall >= 600f) { return(0f); } Vector3 tileCenter = Find.WorldGrid.GetTileCenter(tileID); if (Find.World.GetComponent <WorldComponentExtender>() == null) { WorldComponent item = (WorldComponent)Activator.CreateInstance(typeof(WorldComponentExtender), new object[] { Find.World }); Find.World.components.Add(item); } float tileWeirdness = Find.World.GetComponent <WorldComponentExtender>().noiseWeirdness.GetValue(tileCenter); //Log.Message(tileWeirdness.ToString()); if (tileWeirdness > 0.7f) { return(100f); } else { return(0f); } }
public override float GetScore(Tile tile, int tileID) { if (!AlphaBiomes_Settings.AB_SpawnOcularForest) { return(-100f); } float result; if (tile.WaterCovered) { result = -100f; } else if (tile.temperature < 15f) { result = 0f; } else if (tile.rainfall < 2000f) { result = 0f; } else { Vector3 tileCenter = Find.WorldGrid.GetTileCenter(tileID); if (Find.World.GetComponent <WorldComponentExtender>() == null) { WorldComponent item = (WorldComponent)Activator.CreateInstance(typeof(WorldComponentExtender), new object[] { Find.World }); Find.World.components.Add(item); } float tileWeirdness = Find.World.GetComponent <WorldComponentExtender>().noiseWeirdness.GetValue(tileCenter); //Log.Message(tileWeirdness.ToString()); if (tileWeirdness < 0.15f) { result = 100f; } else { result = 0f; } } return(result); }
// Helper method for creating an empty verb manager for a pawn private static object CreateAndAddVerbManagerToCollections(Pawn pawn, WorldComponent worldComponent, object list = null, object table = null) { var verbManager = mvcfVerbManagerCtor.Invoke(Array.Empty <object>()); if (list == null) { list = mvcfAllManagersListField.GetValue(worldComponent); } if (table == null) { table = mvcfManagersTableField.GetValue(worldComponent); } conditionalWeakTableAddMethod.Invoke(table, new object[] { pawn, verbManager }); ((IList)list).Add(weakReferenceCtor.Invoke(new object[] { verbManager })); return(verbManager); }
void RenderTiles(RenderHelper renderHelper) { ComponentManager cm = ComponentManager.GetInstance(); WorldComponent world = (from w in cm.GetComponentsOfType <WorldComponent>().Values select w).First() as WorldComponent; Viewport viewport = Extensions.GetCurrentViewport(renderHelper.graphicsDevice); Rectangle viewportBounds = viewport.Bounds; foreach (var tile in world.Tiles) { Point point = new Point(tile.Key.X * tile.Value.Width, tile.Key.Y * tile.Value.Height); Rectangle tileBounds = new Rectangle(point.X, point.Y, tile.Value.Width, tile.Value.Height); if (viewportBounds.Intersects(tileBounds)) { renderHelper.spriteBatch.Draw(tile.Value, point.WorldToScreen(ref viewport).ToVector2(), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, (float)RenderLayer.Tiles); } } }
public bool AwareOfObject(WorldComponent obj) { RaycastHit2D hit = Physics2D.Linecast(transform.position, obj.transform.position); float dist = Vector2.Distance(transform.position, obj.transform.position); //Debug.Log("hit dist " + hit.distance); //Debug.Log("vision radius " + god.max_radius * listen_percent); if (hit != null) { float vision_radius = god.max_radius * listen_percent; if (vision_radius >= dist) { return(true); } } return(false); }
private void UpdateHypotheticalListenArea() { if (this != god.GetActiveNPC()) { return; } Collider2D[] col = Physics2D.OverlapCircleAll(transform.position, god.GetHypotheticalPercent() * god.max_radius); //Debug.Log(col.Length); for (int i = 0; i < col.Length; ++i) { WorldComponent wc = col[i].gameObject.GetComponent <WorldComponent>(); if (wc != null) { wc.TurnOn(); wc.SetColored(true); } } }
// Use this for initialization void Start() { PreInit(); World = new World(200, 200); world.SetRegistry(); GameObject worldObject = new GameObject(); WorldComponent worldComponent = worldObject.AddComponent <WorldComponent>(); GameObject overlayObject = new GameObject(); OverlayComponent overlayComponent = overlayObject.AddComponent <OverlayComponent>(); world.Connect(worldComponent); world.Connect(overlayComponent); world.Generate(); cameraController.Center(); }
public override float GetScore(Tile tile, int tileID) { if (!AlphaBiomes_Settings.AB_SpawnGelatinousSuperorganism) { return(-100f); } if (tile.WaterCovered) { return(-100f); } if (tile.temperature < -10f) { return(0f); } if (tile.rainfall < 600f) { return(0f); } Vector3 tileCenter = Find.WorldGrid.GetTileCenter(tileID); if (Find.World.GetComponent <WorldComponentExtender>() == null) { WorldComponent item = (WorldComponent)Activator.CreateInstance(typeof(WorldComponentExtender), new object[] { Find.World }); Find.World.components.Add(item); } float tileWeirdness = Find.World.GetComponent <WorldComponentExtender>().noiseWeirdness.GetValue(tileCenter); //Log.Message(tileWeirdness.ToString()); if (tileWeirdness > 0.75f) { return(100f); } else { return(0f); } //return 15f + (tile.temperature - 7f) + (tile.rainfall - 600f) / 180f + tile.swampiness * 10f; }
public override float GetScore(Tile tile, int tileID) { if (!AlphaBiomes_Settings.AB_SpawnMechanoidIntrusion) { return(-100f); } if (tile.WaterCovered) { return(-100f); } if ((tile.temperature < 17f) || (tile.temperature > 25f)) { return(0f); } if (tile.rainfall < 600f) { return(0f); } Vector3 tileCenter = Find.WorldGrid.GetTileCenter(tileID); if (Find.World.GetComponent <WorldComponentExtender>() == null) { WorldComponent item = (WorldComponent)Activator.CreateInstance(typeof(WorldComponentExtender), new object[] { Find.World }); Find.World.components.Add(item); } float tileRadiation = Find.World.GetComponent <WorldComponentExtender>().noiseRadiation.GetValue(tileCenter); // Log.Message(tileRadiation.ToString()); if (tileRadiation > 0.75f) { return(101f); } else { return(0f); } //return 16f + (tile.temperature - 7f) + (tile.rainfall - 600f) / 180f; }
public void Run() { WorldComponent world = _world.Components1[0]; foreach (int i in _moveableObjects) { Vector2Int newPosition = _moveableObjects.Components1[i].NewPosition; int movableEntity = _moveableObjects.Entities[i]; foreach (int entity in world.WorldField[newPosition.x][newPosition.y]) { var portal = _ecsWorld.GetComponent <PortalComponent>(entity); if (portal == null || portal.EstimateReloadTime > 0) { continue; } int otherPortalEntity = portal.OtherPortalEntity; var otherPortal = _ecsWorld.GetComponent <PortalComponent>(otherPortalEntity); Vector2Int otherPortalPosition = _ecsWorld .GetComponent <PositionComponent>(otherPortalEntity) .Position; _ecsWorld.AddComponent <TeleportingComponent>(movableEntity).NewPosition = otherPortalPosition; portal.EstimateReloadTime = PORTAL_RELOAD_TIME; otherPortal.EstimateReloadTime = PORTAL_RELOAD_TIME; } } foreach (int i in _portals) { PortalComponent portalComponent = _portals.Components1[i]; if (portalComponent.EstimateReloadTime > 0) { portalComponent.EstimateReloadTime -= Time.deltaTime; } } }
public void Run() { WorldComponent world = _world.Components1[0]; foreach (int i in _players) { Vector2Int newPosition = _players.Components1[i].NewPosition; int playerEntity = _players.Entities[i]; foreach (int entity in world.WorldField[newPosition.x][newPosition.y]) { var item = _ecsWorld.GetComponent <ItemComponent>(entity); if (item == null) { continue; } _ecsWorld.AddComponent <TakenItemComponent>(entity).PlayerEntity = playerEntity; _ecsWorld.AddComponent <DestroyedWorldObjectComponent>(entity); } } }
public void Run() { WorldComponent world = _world.Components1[0]; foreach (int i in _createEvents) { Transform newObject = _createEvents.Components1[i].Transform; int entity = _createEvents.Entities[i]; Vector2Int position = newObject.position.ToVector2Int(); world.WorldField[position.x][position.y].Add(entity); _ecsWorld.AddComponent <PositionComponent>(entity).Position = position; _ecsWorld.AddComponent <WorldObjectComponent>(entity).Transform = newObject; } foreach (int i in _movedObjects) { PositionComponent positionComponent = _movedObjects.Components1[i]; Vector2Int oldPosition = positionComponent.Position; Vector2Int newPosition = _movedObjects.Components2[i].NewPosition; int entity = _movedObjects.Entities[i]; world.WorldField[oldPosition.x][oldPosition.y].Remove(entity); world.WorldField[newPosition.x][newPosition.y].Add(entity); positionComponent.Position = newPosition; } foreach (int i in _destroyedObjects) { Transform objectToDestroy = _destroyedObjects.Components1[i].Transform; Vector2Int position = _destroyedObjects.Components2[i].Position; int entity = _destroyedObjects.Entities[i]; world.WorldField[position.x][position.y].Remove(entity); objectToDestroy.gameObject.SetActive(false); _ecsWorld.RemoveEntity(entity); } }
public static void WorldComponentListTick() { while (true) { int index = Interlocked.Decrement(ref worldComponentTicks); if (index < 0) { return; } WorldComponent worldComponent = worldComponents[index]; if (null != worldComponent) //TODO: is null-check and lock necessary? { try { worldComponent.WorldComponentTick(); } catch (Exception ex) { Log.Error("Exception ticking World Component: " + worldComponent.ToStringSafe() + ex); } } } }
private static object InitVerbManager(Pawn pawn, WorldComponent comp = null, object list = null, object table = null) { if (comp == null) { comp = (WorldComponent)mvcfGetWorldCompMethod.Invoke(null, Array.Empty <object>()); } if (comp == null) { return(null); } if (table == null) { table = mvcfManagersTableField.GetValue(comp); } var parameters = new object[] { pawn, null }; object verbManager; // Try to find the verb manager first, as it might exist (and it will definitely exist for at least one player) if ((bool)conditionalWeakTableTryGetValueMethod.Invoke(table, parameters)) { verbManager = parameters[1]; // If the manager has the pawn assigned, it means it's initialized, if it's not - we initialize it if (mvcfPawnGetter.Invoke(verbManager, Array.Empty <object>()) == null) { mvcfInitializeManagerMethod.Invoke(verbManager, new object[] { pawn }); } } // If the verb manager doesn't exist, we create an empty one here and add it to the verb manager list and table, and then initialize it else { verbManager = CreateAndAddVerbManagerToCollections(pawn, comp, list, table); mvcfInitializeManagerMethod.Invoke(verbManager, new object[] { pawn }); } return(verbManager); }
public static EntityComponent SpawnEntityControllerInWorld( WorldComponent worldComponent, Entity entity, Vector2 coord) { GameObject entityObject = new GameObject(); EntityComponent entityComponent = entityObject.AddComponent <EntityComponent>(); entityObject.transform.SetParent(worldComponent.transform); //entityComponent.SetPosition(coord); PolygonCollider2D collider = entityObject.AddComponent <PolygonCollider2D>(); collider.points = new Vector2[] { new Vector2(-0.5f, -0.5f), new Vector2(-0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, -0.5f) }; entityComponent.spriteRenderer = entityObject.AddComponent <SpriteRenderer>(); entityComponent.spriteRenderer.sprite = SpriteLoader.GetSprite("test"); return(entityComponent); }
public void Run() { GhostConfigComponent ghostConfig = _ghostConfig.Components1[0]; WorldComponent world = _world.Components1[0]; if (_enableEvents.EntitiesCount > 0) { foreach (int i in _ghosts) { GameObject ghost = _ghosts.Components2[i].Transform.gameObject; int ghostEntity = _ghosts.Entities[i]; bool isNew; _ecsWorld .EnsureComponent <GhostInFearStateComponent>(ghostEntity, out isNew) .EstimateTime = ghostConfig.FearStateInSec; if (isNew) { ghost.GetComponent <MeshRenderer>().material.color = ghostConfig.FearState; } } } foreach (int i in _fearStateGhosts) { GhostComponent ghostComponent = _fearStateGhosts.Components1[i]; GhostInFearStateComponent fearState = _fearStateGhosts.Components2[i]; GameObject ghost = _fearStateGhosts.Components3[i].Transform.gameObject; int ghostEntity = _fearStateGhosts.Entities[i]; fearState.EstimateTime -= Time.deltaTime; if (fearState.EstimateTime <= 0) { _ecsWorld.RemoveComponent <GhostInFearStateComponent>(ghostEntity); var material = ghost.GetComponent <MeshRenderer>().material; switch (ghostComponent.GhostType) { case GhostTypes.BLINKY: material.color = ghostConfig.Blinky; break; case GhostTypes.PINKY: material.color = ghostConfig.Pinky; break; case GhostTypes.INKY: material.color = ghostConfig.Inky; break; case GhostTypes.CLYDE: material.color = ghostConfig.Clyde; break; default: throw new ArgumentOutOfRangeException(); } return; } Vector2Int currentPosition = _ecsWorld.GetComponent <PositionComponent>(ghostEntity).Position; foreach (int entity in world.WorldField[currentPosition.x][currentPosition.y]) { var player = _ecsWorld.GetComponent <PlayerComponent>(entity); if (player == null) { continue; } player.Scores += ghostConfig.ScoresPerGhost; _ecsWorld.CreateEntityWith <UpdateScoreTableEvent>(); _ecsWorld.AddComponent <DestroyedWorldObjectComponent>(ghostEntity); } } }
public void ApplyCamera(BasicEffect effect, WorldComponent component) { effect.View = State.Camera.View; effect.Projection = State.Camera.Projection; effect.World = component.World; }