Ejemplo n.º 1
0
 public void Tick()
 {
     if (SpawnedObjectId == default ||
         CurrentServer.GetGhost(SpawnedObjectId) == null)
     {
         SpawnedObjectId = CurrentServer.Create(EntityObjectsMap.GetTypeFromDef(((SimpleSpawnerDef)Def).ObjectToSpawn.Def),
                                                (ent) =>
         {
             if (ent is IPositionedEntity)
             {
                 ((IPositionedEntity)ent).Position = Position;
             }
             ((IEntityObject)ent).Def = ((SimpleSpawnerDef)Def).ObjectToSpawn.Def;
         });
     }
 }
Ejemplo n.º 2
0
        public void Apply(ScriptingContext ctx)
        {
            var point = Where.Def.Select(ctx);

            ctx.ProcessingEntity.CurrentServer.Create(EntityObjectsMap.GetTypeFromDef(Object.Def),
                                                      (ent) =>
            {
                if (ent is IPositionedEntity)
                {
                    ((IPositionedEntity)ent).Position = point;
                }
                ((IEntityObject)ent).Def = Object.Def;
                if (Buffed != null)
                {
                    ((IHasSpells)ent).SpellsEngine.DynamicBuffsOnStart = new List <SpellDef>(new[] { Buffed.Def });
                }
            });
        }
Ejemplo n.º 3
0
 public void Update()
 {
     try
     {
         if (firstTime)
         {
             var r = new Random(0);
             firstTime = false;
             foreach (var site in _debugCreator.Sites)
             {
                 if (site.Def.Type.Def != null && site.Def.Type.Def.EntitiesToSpawnOn.Count > 0)
                 {
                     var randomEntity = site.Def.Type.Def.EntitiesToSpawnOn[r.Next(site.Def.Type.Def.EntitiesToSpawnOn.Count)].Def;
                     var objId        = _node.Create(EntityObjectsMap.GetTypeFromDef(randomEntity), e =>
                     {
                         ((IEntityObject)e).Def          = randomEntity;
                         ((IPositionedEntity)e).Position = site.GlobalPos;
                         ((IPositionedEntity)e).Rotation = site.GlobalRot;
                     });
                     if (site.Def.AttachedScene != null)
                     {
                         _node.Create <SceneEntity>(se =>
                         {
                             se.Position = site.GlobalPos;
                             se.Rotation = site.GlobalRot;
                             se.SceneDef = site.Def.AttachedScene;
                         });
                     }
                 }
             }
             if (_debugCreator._rootInstance.Def.AttachedScene != null)
             {
                 _node.Create <SceneEntity>(se =>
                 {
                     se.Position = _debugCreator._rootInstance.GlobalPos;
                     se.Rotation = _debugCreator._rootInstance.GlobalRot;
                     se.SceneDef = _debugCreator._rootInstance.Def.AttachedScene;
                 });
             }
         }
         var deltaTime = EnvironmentAPI.Time.DeltaTime;
         foreach (var ghost in _node.AllGhosts())
         {
             if (ghost is ICharacterLikeMovement charLikeMovement)
             {
                 if (charLikeMovement.PhysicsBody == null)
                 {
                     var pos = ((IPositionedEntity)ghost).Position;
                     lock (_physicsWorld)
                     {
                         var circleShape = _physicsWorld.CreateCircleWorldSpace(new Vector2(pos.X, pos.Y), 1f, 1);
                         var body        = _physicsWorld.CreateDynamicBody(new Vector2(pos.X, pos.Y), 1, circleShape);
                         body.UserData = ghost.Id;
                         charLikeMovement.PhysicsBody = body;
                     }
                 }
                 charLikeMovement.InterpolationUpdate(deltaTime);
             }
         }
         var tick = _node.Tick();
         lock (_physicsWorld)
         {
             _physicsWorld.DeltaTime = EnvironmentAPI.Time.DeltaTime;
             _physicsWorld.Update();
         }
         tick.Wait();
     }
     catch (Exception e)
     {
         Logger.LogError?.Invoke(e.ToString());
     }
 }