protected ScriptFieldEntity(Owner owner, FieldEntity parent = null) : base(owner, parent)
        {
            Script = new Script(CoreModules.Preset_HardSandbox);
            RegisterScript(DefaultScript);

            RegisterAction <FieldEntity>("mg_queue_registration", MgQueueRegistration);
            RegisterAction <FieldEntity>("mg_queue_deregistration", MgQueueDeregistration);
            RegisterFunction <Guid, FieldEntity>("mg_find_entity", MgFindEntity);
            RegisterFunction <Cell2, FieldEntity>("mg_check_primary_entity", MgCheckPrimaryEntity);
            RegisterFunction <Cell2, bool>("mg_check_warn_cell", MgCheckWarnCell);
            RegisterAction <FieldEvent>("mg_send_event", MgSendEvent);
            RegisterFunction <Cell2, Cell2, int, FieldEntity>("mg_scan_primary", MgScanPrimary);
            RegisterFunction <Cell2, Cell2, int, IEnumerable <FieldEntity> >("mg_scan_primary_multi", MgScanPrimaryMulti);
            RegisterAction <Sound>("mg_play_sound", MgPlaySound);
            RegisterAction <Sound>("mg_pause_sound", MgPauseSound);
            RegisterAction <Sound>("mg_stop_sound", MgStopSound);

            RegisterFunction <string, bool>("nt_has_timer", NtHasTimer);
            RegisterFunction <string, FTimer>("nt_get_timer", NtGetTimer);
            RegisterFunction <string, float, FTimer>("nt_add_timer", NtAddTimer);
            RegisterAction <string>("nt_remove_timer", NtRemoveTimer);
            RegisterAction <FieldEntity, Cell2, float>("ntx_configure_position_static", NtxConfigurePositionStatic);
            RegisterAction <FieldEntity, float, float, Cell2, Cell2, float, float>("ntx_configure_position_linear",
                                                                                   NtxConfigurePositionLinear);
            RegisterAction <FieldEntity, float, float, Cell2, Cell2, float, float, float>("ntx_configure_position_quad",
                                                                                          NtxConfigurePositionQuad);
            RegisterAction <FieldEntity, string, string, float, float, float, bool, bool>("ntx_configure_visual_state",
                                                                                          NtxConfigureVisualState);
            RegisterAction <FieldEntity, Cell2, HitBox.AvoidType, bool, bool>("ntx_configure_hit_box",
                                                                              NtxConfigureHitBox);
        }
Beispiel #2
0
        private void AddEntity(FieldEntity entity)
        {
            if (entity.Manager == this)
            {
                return;
            }
            entity.Manager = this;
            AddEntityToOwnerDict(entity.Owner, entity);
            AddEntityToGrid(entity.HitBox, entity);
            _fieldEntities.Add(entity);
            _fieldEntitiesGuid.Add(entity.Id, entity);
            AddEntityWarnCells(entity.WarnCells, entity);
            var bOwner = entity.Owner.BaseName;

            if (bOwner == null)
            {
                return;
            }
            if (_ownerDict.TryGetValue(bOwner, out var entities))
            {
                entities.Add(entity);
            }
            else
            {
                _ownerDict[bOwner] = new HashSet <FieldEntity> {
                    entity
                }
            };
        }
Beispiel #3
0
 internal void EntityOwnerChange(FieldEntity entity, Owner previousOwner, Owner targetOwner)
 {
     if (entity.Manager != this)
     {
         return;
     }
     RemoveEntityFromOwnerDict(previousOwner, entity);
     AddEntityToOwnerDict(targetOwner, entity);
 }
Beispiel #4
0
 internal void EntityWarnCellChange(FieldEntity entity, ICollection <Cell2> previousWarnCells,
                                    ICollection <Cell2> targetWarnCells)
 {
     if (entity.Manager != this)
     {
         return;
     }
     RemoveEntityWarnCells(previousWarnCells, entity);
     AddEntityWarnCells(targetWarnCells, entity);
 }
        private static void NtxConfigurePositionQuad(FieldEntity entity, float baseTime, float targetTime,
                                                     Cell2 srcCell,
                                                     Cell2 targetCell, float height1, float height2, float arcHeight)
        {
            var a = new FVector3(srcCell.X, srcCell.Y, height1);
            var c = new FVector3(targetCell.X, targetCell.Y, height2);
            var b = FVector3.Midpoint(a, c);

            b = new FVector3(b.X, b.Y, arcHeight);
            entity.Position = new Position(a, b, c, baseTime, targetTime);
        }
Beispiel #6
0
 private void AddEntityToOwnerDict(Owner owner, FieldEntity entity)
 {
     if (owner.BaseName == null)
     {
         return;
     }
     if (!_ownerDict.TryGetValue(owner.BaseName, out var entities))
     {
         entities = _ownerDict[owner.BaseName] = new HashSet <FieldEntity>();
     }
     entities.Add(entity);
 }
Beispiel #7
0
        private void AddEntityToGrid(HitBox hitBox, FieldEntity entity)
        {
            var cell = (long)hitBox.Position;

            if (!_gridEntities.TryGetValue(cell, out var set))
            {
                set = _gridEntities[cell] = new HashSet <FieldEntity>();
            }
            set.Add(entity);
            if (!hitBox.Primary)
            {
                return;
            }
            _gridPrimaryEntities[cell] = entity;
        }
Beispiel #8
0
 private void AddEntityWarnCells(ICollection <Cell2> warnCells, FieldEntity entity)
 {
     if (warnCells == null)
     {
         return;
     }
     foreach (var cell in warnCells)
     {
         if (!_gridWarnCells.TryGetValue((long)cell, out var set))
         {
             set = _gridWarnCells[(long)cell] = new HashSet <FieldEntity>();
         }
         set.Add(entity);
     }
 }
Beispiel #9
0
        internal bool EntityHitBoxChange(FieldEntity entity, HitBox previousHitBox, HitBox targetHitBox)
        {
            if (entity.Manager != this)
            {
                return(false);
            }
            var targetPos = (long)targetHitBox.Position;

            if (targetHitBox.Primary && _gridPrimaryEntities.TryGetValue(targetPos, out var res))
            {
                return(res == entity);
            }
            RemoveEntityFromGrid(previousHitBox, entity);
            AddEntityToGrid(targetHitBox, entity);
            return(true);
        }
Beispiel #10
0
 private void RemoveEntityFromOwnerDict(Owner owner, FieldEntity entity)
 {
     if (owner.BaseName == null)
     {
         return;
     }
     if (!_ownerDict.TryGetValue(owner.BaseName, out var set))
     {
         return;
     }
     set.Remove(entity);
     if (set.Count == 0)
     {
         _ownerDict.Remove(owner.BaseName);
     }
 }
Beispiel #11
0
        private void RemoveEntityFromGrid(HitBox hitBox, FieldEntity entity)
        {
            var cell = (long)hitBox.Position;

            if (!_gridEntities.TryGetValue(cell, out var set))
            {
                return;
            }
            set.Remove(entity);
            if (set.Count == 0)
            {
                _gridEntities.Remove(cell);
            }
            if (hitBox.Primary && _gridPrimaryEntities.TryGetValue(cell, out var res) && res == entity)
            {
                _gridPrimaryEntities.Remove(cell);
            }
        }
Beispiel #12
0
 private void RemoveEntityWarnCells(ICollection <Cell2> warnCells, FieldEntity entity)
 {
     if (warnCells == null)
     {
         return;
     }
     foreach (var cell in warnCells)
     {
         if (!_gridWarnCells.TryGetValue((long)cell, out var set))
         {
             continue;
         }
         set.Remove(entity);
         if (set.Count == 0)
         {
             _gridWarnCells.Remove((long)cell);
         }
     }
 }
Beispiel #13
0
        private void RemoveEntity(FieldEntity entity)
        {
            if (entity.Manager != this)
            {
                return;
            }
            entity.Manager = null;
            RemoveEntityFromOwnerDict(entity.Owner, entity);
            RemoveEntityFromGrid(entity.HitBox, entity);
            _fieldEntities.Remove(entity);
            _fieldEntitiesGuid.Remove(entity.Id);
            RemoveEntityWarnCells(entity.WarnCells, entity);
            if (!entity.HitBox.Primary)
            {
                return;
            }
            var pos = (long)entity.HitBox.Position;

            if (_gridPrimaryEntities.TryGetValue(pos, out var gridEntity) && gridEntity == entity)
            {
                _gridPrimaryEntities.Remove(pos);
            }
        }
Beispiel #14
0
 private static void NtxConfigurePositionStatic(FieldEntity entity, Cell2 cell, float height) =>
 entity.Position = new Position(new FVector3(cell.X, cell.Y, height));
Beispiel #15
0
 private static void NtxConfigureVisualState(FieldEntity entity, string asset, string animation, float baseTime,
                                             float speed, float warp, bool visible, bool enemyVisible) =>
 entity.VisualState = new VisualState(asset, animation, baseTime, speed, warp, visible, enemyVisible);
Beispiel #16
0
 private static void NtxConfigureHitBox(FieldEntity entity, Cell2 cell, HitBox.AvoidType avoidType,
                                        bool targetable, bool primary) => entity.HitBox = new HitBox(cell, avoidType, targetable, primary);
Beispiel #17
0
 private void MgQueueRegistration(FieldEntity entity) => Manager?.QueueRegistration(entity);
Beispiel #18
0
 public void QueueDeregistration(FieldEntity entity) => _deregQueue.Enqueue(entity);
Beispiel #19
0
 private static void NtxConfigurePositionLinear(FieldEntity entity, float baseTime, float targetTime,
                                                Cell2 srcCell,
                                                Cell2 targetCell, float height1, float height2) =>
 entity.Position = new Position(new FVector3(srcCell.X, srcCell.Y, height1),
                                new FVector3(targetCell.X, targetCell.Y, height2), baseTime, targetTime);