コード例 #1
0
 void Update()
 {
     if (Export)
     {
         ExportConstructs("../SwingingGame/Constructs");
         Export = false;
     }
     if (Import)
     {
         ConstList = ImportConstructs("../SwingingGame/Constructs");
         Import    = false;
     }
     if (NewConfig)
     {
         CreateNewConfig();
         NewConfig = false;
     }
     if (Approve)
     {
         ApproveConstruct();
         Approve = false;
     }
     if (ChangeAtIndex)
     {
         Constructs Temp = new Constructs(CurrentConfigs.ToArray(), ConstructName);
         ConstList.RemoveAt(Index);
         ConstList.Insert(Index, Temp);
         Temp = null;
         CurrentConfigs.Clear();
         ChangeAtIndex = false;
     }
 }
コード例 #2
0
    public void ApproveConstruct()
    {
        Constructs Temp = new Constructs(CurrentConfigs.ToArray(), ConstructName);

        ConstList.Add(Temp);
        Temp = null;
        CurrentConfigs.Clear();
    }
コード例 #3
0
        protected override IEnumerable <MemberDeclarationSyntax> Members(T[] instancesAr)
        {
            var grouped = instancesAr.GroupBy(MetadataResolver.GetEntityCategory);

            foreach (var group in grouped)
            {
                yield return(Constructs.Class(string.IsNullOrEmpty(group.Key) ? "All" : group.Key, new[] { SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword }, () => SyntaxFactory.List(@group.Select(CreateConstant))));
            }
        }
コード例 #4
0
        public void RemoveConstruct(Construct construct)
        {
            int index = Constructs.IndexOf(construct);

            if (index >= 0)
            {
                Constructs.RemoveAt(index);
                ConstructDestroyed(construct);
            }
        }
コード例 #5
0
 private IEnumerable <MemberDeclarationSyntax> SubClass(T[] instancesAr)
 {
     yield return(Constructs.Class(SubClassName, new[]
     {
         SyntaxKind.PublicKeyword,
         SyntaxKind.StaticKeyword,
         SyntaxKind.PartialKeyword
     },
                                   () => SyntaxFactory.List(Members(instancesAr))
                                   ));
 }
コード例 #6
0
 public Constructs(Constructs c)
 {
     this.Configurations = new Config[c.Configurations.Length];
     for (int j = 0; j < c.Configurations.Length; j++)
     {
         this.Configurations[j]             = new Config();
         this.Configurations[j].StaticParts = c.Configurations[j].StaticParts;
         this.Configurations[j].MovingParts = new MovingPart[c.Configurations[j].MovingParts.Length];
         for (int i = 0; i < c.Configurations[j].MovingParts.Length; i++)
         {
             this.Configurations[j].MovingParts[i] = new MovingPart(c.Configurations[j].MovingParts[i]);
         }
     }
 }
コード例 #7
0
 private void MoveConstruct(int fromIndex, int toIndex)
 {
     using (UndoTransaction tx = new UndoTransaction(UndoManager))
     {
         ConstructVM fromConstruct = Constructs[fromIndex];
         ConstructVM toConstruct   = Constructs[toIndex];
         if (RenumberQuestionNo && fromConstruct is QuestionConstructVM && toConstruct is QuestionConstructVM)
         {
             QuestionNumberVM fromQuestionNumber = new QuestionNumberVM((QuestionConstructVM)fromConstruct);
             fromQuestionNumber.AfterValue = toConstruct.No;
             QuestionNumberVM toQuestionNumber = new QuestionNumberVM((QuestionConstructVM)toConstruct);
             toQuestionNumber.AfterValue = fromConstruct.No;
             List <QuestionNumberVM> questionNumbers = new List <QuestionNumberVM>();
             questionNumbers.Add(fromQuestionNumber);
             questionNumbers.Add(toQuestionNumber);
             SequenceUtils.RenumberQuestionNumbers(this, questionNumbers);
         }
         Constructs.Move(fromIndex, toIndex);
         UpdateModel(false);
         tx.Commit();
     }
     FocusCell();
 }
コード例 #8
0
        /// <summary>
        /// Funkcja wywoływana przy kazdym odswierzeniu okranu
        /// </summary>
        /// <param name="sender">Obiekt wysylajacy zdazenie</param>
        /// <param name="e">Argumenty zdarzenia</param>
        public void UpdateTime(object sender, UpdateEventArgs e)
        {
            for (int index = 0; index < colonists_.Count;)
            {
                if (colonists_[index].HP.Value > 0f)
                {
                    index++;
                    continue;
                }

                colonists_[index].Die();
                colonists_.Remove(colonists_[index]);
            }

            foreach (Men colonist in Colonist.Where(c => c.Job == null))
            {
                string stateSleep = MakeDecision(colonist.RestF, colonist.Laziness);
                string stateWork  = MakeDecision(colonist.HP, colonist.Laziness);

                if (stateSleep == "Sleep")
                {
                    Bed bed = Constructs.Where(c => c is Bed)
                              .Cast <Bed>()
                              .FirstOrDefault(b => b.State == Construct.Status.Done && b.IsFree);

                    colonist.Job = new SleepJob(colonist, bed);
                }
                else if (stateWork == "Work" && JobQueue.Count > 0)
                {
                    colonist.Job = JobQueue.Dequeue();
                }
                else if (stateWork == "RestF" || colonist.HP != colonist.HP.MaxHP)
                {
                    colonist.Job = colonist.Rest;
                }
            }
        }
コード例 #9
0
        public void Generate(string definedInNamespace, IEnumerable <T> instances, string file)
        {
            var instancesAr = instances.ToArray();

            var member = new[]
            {
                Constructs.Class(MetadataResolver.DataDirectoryToOperateIn, new[]
                {
                    SyntaxKind.PublicKeyword,
                    SyntaxKind.StaticKeyword,
                    SyntaxKind.PartialKeyword
                },
                                 () => SyntaxFactory.List(SubClass(instancesAr))
                                 )
            };

            var namespaces = instancesAr.Select(i => i.GetType().Namespace)
                             .Union(Mapper.FoundTypes.SelectMany(ExtractNamespaces))
                             .Except(new[] { "System" })
                             .Distinct();

            var codeFile = new CodeFile
            {
                DefinedInNamespace = definedInNamespace,
                UsingNamespaces    = namespaces,
                ClassName          = "Factory",
                AccessModifiers    = new[]
                {
                    SyntaxKind.PublicKeyword,
                    SyntaxKind.StaticKeyword,
                    SyntaxKind.PartialKeyword
                },
                Members = () => member
            };

            File.WriteAllText(file, codeFile.Definition());
        }
コード例 #10
0
ファイル: CompRun.cs プロジェクト: sstixrud/WeaponCore
        internal void ReInit()
        {
            using (MyCube.Pin())  {
                if (!MyCube.MarkedForClose && Entity != null)
                {
                    GridAi ai;
                    if (!Session.GridTargetingAIs.TryGetValue(MyCube.CubeGrid, out ai))
                    {
                        var newAi = Session.GridAiPool.Get();
                        newAi.Init(MyCube.CubeGrid, Session);
                        Session.GridTargetingAIs[MyCube.CubeGrid] = newAi;
                        Ai = newAi;
                    }
                    else
                    {
                        Ai = ai;
                    }

                    if (Ai != null)
                    {
                        Ai.FirstRun = true;

                        if (Platform.State == MyWeaponPlatform.PlatformState.Inited)
                        {
                            Platform.ResetParts(this);
                        }

                        Entity.NeedsWorldMatrix = true;

                        // ReInit Counters
                        var blockDef = MyCube.BlockDefinition.Id.SubtypeId;
                        if (!Ai.WeaponCounter.ContainsKey(blockDef)) // Need to account for reinit case
                        {
                            Ai.WeaponCounter[blockDef] = Session.WeaponCountPool.Get();
                        }

                        var wCounter = Ai.WeaponCounter[blockDef];
                        wCounter.Max = Platform.Structure.GridWeaponCap;

                        wCounter.Current++;
                        Constructs.UpdateWeaponCounters(Ai);
                        // end ReInit

                        if (!Ai.GridInit || !Ai.Session.GridToInfoMap.ContainsKey(Ai.MyGrid))
                        {
                            Session.CompReAdds.Add(new CompReAdd {
                                Ai = Ai, AiVersion = Ai.Version, AddTick = Ai.Session.Tick, Comp = this
                            });
                        }
                        else
                        {
                            OnAddedToSceneTasks();
                        }
                    }
                    else
                    {
                        Log.Line($"Comp ReInit() failed stage2!");
                    }
                }
                else
                {
                    Log.Line($"Comp ReInit() failed stage1! - marked:{MyCube.MarkedForClose} - Entity:{Entity != null} - hasAi:{Session.GridTargetingAIs.ContainsKey(MyCube.CubeGrid)}");
                }
            }
        }
コード例 #11
0
 public void RemoveConstruct()
 {
     Constructs.Remove(SelectedConstruct);
     UpdateModel(true);
 }
コード例 #12
0
 public bool Sync(Constructs construct, ConstructDataValues sync, bool localCall = false)
 {
     FocusData.Sync(construct.RootAi, sync.FocusData, localCall);
     return(true);
 }
コード例 #13
0
        internal void RemoveComp()
        {
            try {
                if (Registered)
                {
                    RegisterEvents(false);
                }

                if (Ai != null)
                {
                    Ai.OptimalDps   -= PeakDps;
                    Ai.EffectiveDps -= EffectiveDps;

                    WeaponCount wCount;
                    if (Ai.WeaponCounter.TryGetValue(MyCube.BlockDefinition.Id.SubtypeId, out wCount))
                    {
                        wCount.Current--;
                        Constructs.UpdateWeaponCounters(Ai);
                        if (wCount.Current == 0)
                        {
                            Ai.WeaponCounter.Remove(MyCube.BlockDefinition.Id.SubtypeId);
                            Session.WeaponCountPool.Return(wCount);
                        }
                    }
                    else if (Session.LocalVersion)
                    {
                        Log.Line($"didnt find counter for: {MyCube.BlockDefinition.Id.SubtypeId} - MarkedForClose:{Ai.MarkedForClose} - AiAge:{Ai.Session.Tick - Ai.AiSpawnTick} - CubeMarked:{MyCube.MarkedForClose} - GridMarked:{MyCube.CubeGrid.MarkedForClose}");
                    }

                    if (Ai.Data.Repo.ActiveTerminal == MyCube.EntityId)
                    {
                        Ai.Data.Repo.ActiveTerminal = 0;
                    }

                    GridAi          testAi;
                    WeaponComponent comp;
                    if (Ai.WeaponBase.TryRemove(MyCube, out comp))
                    {
                        if (Platform.State == MyWeaponPlatform.PlatformState.Ready)
                        {
                            for (int i = 0; i < comp.Platform.Weapons.Length; i++)
                            {
                                var w = comp.Platform.Weapons[i];
                                w.StopShooting();
                                w.WeaponCache.HitEntity.Clean();
                                if (!Session.IsClient)
                                {
                                    w.Target.Reset(Session.Tick, Target.States.AiLost);
                                }
                                if (w.DrawingPower)
                                {
                                    w.StopPowerDraw();
                                }
                            }
                        }
                        Ai.CompChange(false, this);
                    }
                    else
                    {
                        Log.Line($"RemoveComp Weaponbase didn't have my comp: {Ai.Session.CompsDelayed.Contains(this)} - FoundAi:{Ai.Session.GridTargetingAIs.TryGetValue(MyCube.CubeGrid, out testAi)} - sameAi:{testAi == Ai}");
                    }

                    if (Ai.WeaponBase.Count == 0)
                    {
                        GridAi gridAi;
                        Session.GridTargetingAIs.TryRemove(Ai.MyGrid, out gridAi);
                    }

                    Ai = null;
                }
                else if (Platform.State != MyWeaponPlatform.PlatformState.Delay)
                {
                    Log.Line($"CompRemove: Ai already null - State:{Platform.State} - Status:{Status}");
                }
            }
            catch (Exception ex) { Log.Line($"Exception in RemoveComp: {ex} - AiNull:{Ai == null} - SessionNull:{Session == null}"); }
        }
コード例 #14
0
ファイル: AiSupport.cs プロジェクト: Coreman230/WeaponCore
 internal void UpdateConstruct()
 {
     Construct = new Constructs(this);
 }
コード例 #15
0
 public Construct GetConstruct(string id)
 => Constructs?.FirstOrDefault(x => x.Id == id);
コード例 #16
0
 // constructs
 public void AddConstruct(Construct construct)
 {
     Constructs.Add(construct);
     NewConstructBuilt(construct);
 }