示例#1
0
        public override void Update()
        {
            if (Objects.Count <Arena>() > 0)
            {
                Borderless = true;
            }

            if (Input.KeyboardCheckPress(Controls.KeyA) || Input.KeyboardCheckPress(Controls.KeyB))
            {
                if (_dialogueLines[LineId].Length != _typedText.ToString().Length)
                {
                    _typedText = new StringBuilder(_dialogueLines[LineId]);
                }
                else
                {
                    if (!Locked)
                    {
                        LineId += 1;
                        _typedText.Clear();
                        if (LineId >= _dialogueLines.Length)
                        {
                            LineId           = _dialogueLines.Length - 1;
                            Controls.Enabled = true;
                            Objects.Destroy(this);
                            Input.KeyboardClear();
                        }
                    }
                }
            }

            if (_dialogueLines[LineId].Length != _typedText.ToString().Length)
            {
                _typeAlarm.Update();
                if (!_typeAlarm.Active)
                {
                    _typeAlarm.Set(_typeSpeed);
                }
                if (_typeAlarm.Triggered)
                {
                    if (!Voiceless)
                    {
                        SoundController.PlaySound(SoundController.Voice);
                    }

                    _typedText.Append(_dialogueLines[LineId].ElementAt(_typedText.Length));
                    if (_dialogueLines[LineId].Length - 1 > _typedText.Length)
                    {
                        char nextCh = _dialogueLines[LineId].ElementAt(_typedText.Length);
                        if (nextCh == ' ')
                        {
                            _typedText.Append(' ');
                        }
                        if (nextCh == Environment.NewLine.ElementAt(0))
                        {
                            _typedText.Append(Environment.NewLine);
                        }
                    }
                }
            }
        }
示例#2
0
 private static void Static_Game_GameStep()
 {
     if (--countTimer <= 0)
     {
         foodCount  = Objects.Count(x => x is Food);
         countTimer = 1000;
     }
 }
 /// <summary>
 /// Check if user selected a Value in <see cref="MetroFrameworkComboBox"/>
 /// </summary>
 /// <returns></returns>
 public bool HasValue()
 {
     if (Objects.Count() < 1)
     {
         //No Objects
         return(!string.IsNullOrEmpty(Text));
     }
     return(!string.IsNullOrEmpty(_value) && Objects.Any(x => x.Text == _value));
 }
示例#4
0
        public override async Task Trigger()
        {
            //Trace.WriteLine("Event triggered: " + AttributeName);
            //foreach (Ear.Action action in Objects.OfType<Ear.Action>())
            //{
            //    await action.Execute(Context);
            //}

            // Only execute the action corresponding to our zone
            if (Objects.Count() > iActionIndex)
            {
                await((Ear.Action)Objects[iActionIndex]).Execute(Context);
            }
        }
示例#5
0
        /// <summary>
        /// Returns whether this CardSpot is full and cannot take any more cards
        /// </summary>
        public bool IsFull(bool includeJokers)
        {
            if (Type == SpotType.NONE)
            {
                return(false);
            }

            int count = Objects.Count(c => !c.IsJoker() || includeJokers);

            if (Type == SpotType.RUN)
            {
                return(count == 14);
            }
            // else SpotType.SET
            return(count == 4);
        }
        public bool Validate()
        {
            if (Objects == null)
            {
                return(true);
            }

            var count   = Objects.Count();
            var isValid = true;

            for (int i = 0; i < count; i++)
            {
                var obj = (JObject)Objects[i];


                isValid = ChildValidators.Select(validate => validate(obj, 0)).Aggregate(true, (a, b) => a && b) && isValid;
                string discriminatorValue = obj.SelectToken($"$.{Dicriminator}")?.ToString();

                if (discriminatorValue == null)
                {
                    RaiseError(new SchemaValidationError(
                                   path: $"{Path}[{i}]",
                                   message: $"Required property {Dicriminator} is missing."
                                   ));
                    continue;
                }

                try
                {
                    var schema = Schemas[discriminatorValue];
                    var errors = schema.Validate(obj);
                    isValid = isValid && errors.Count() == 0;

                    RaiseErrors(errors, $"{Path}[{i}]");
                }
                catch (KeyNotFoundException)
                {
                    RaiseError(new SchemaValidationError(
                                   path: $"{Path}[{i}].{Dicriminator}",
                                   message: $"Property {Dicriminator} can only be one of the following: {string.Join(", ", Schemas.Keys)}. (found {discriminatorValue})"

                                   ));
                    continue;
                }
            }
            return(isValid);
        }
        public bool Validate()
        {
            if (Objects == null)
            {
                return(true);
            }

            var count   = Objects.Count();
            var isValid = true;

            for (int i = 0; i < count; i++)
            {
                var obj = (JObject)Objects[i];

                var value = obj.GetValue(Property);

                var ids = value switch
                {
                    JValue single => new string[] { single.ToString() },
                    JArray multiple => multiple.ToObject <string[]>()
                };

                ids.Where(id => !KnownIds.Contains(id))
                .ToList()
                .ForEach(id => {
                    isValid = false;
                    RaiseError(new SchemaValidationError(
                                   path: $"{Path}[{i}].{Property}",
                                   message: $"Referenced {Entity} id does not exist. Has to be one of: {string.Join(", ", KnownIds)}. (found {id})"

                                   ));
                });
            }

            return(isValid);
        }
    }
示例#8
0
        private bool LoadCryopodEntries()
        {
            int nextObjectId = 0;

            //parse any vivarium creatures
            var  vivariumList = Objects.Where(o => o.ClassName.Name == "BP_Vivarium_C" && o.Location != null).ToList();
            Guid currentId    = Guid.Empty;

            foreach (var vivarium in vivariumList)
            {
                if (!currentId.Equals(vivarium.Uuid))
                {
                    currentId = vivarium.Uuid;

                    //get dino data (PropertyArray)
                    if (vivarium.Properties.ContainsKey(_dinoDataList))
                    {
                        PropertyArray dinoArray = vivarium.GetProperty <PropertyArray>(_dinoDataList);
                        foreach (StructPropertyList dinoData in dinoArray.Value)
                        {
                            if (dinoData.Properties.ContainsKey(_dinoData))
                            {
                                PropertyArray dinoDetails = dinoData.GetProperty <PropertyArray>(_dinoData);

                                nextObjectId = Objects.Count();
                                sbyte[] sbyteData = dinoDetails.Value.Cast <sbyte>().ToArray();
                                byte[]  byteData  = (byte[])(Array)sbyteData;


                                using (MemoryMappedFile cryoMmf = MemoryMappedFile.CreateNew(null, byteData.Length))
                                {
                                    using (MemoryMappedViewStream stream = cryoMmf.CreateViewStream())
                                    {
                                        BinaryWriter writer = new BinaryWriter(stream);
                                        writer.Write(byteData);
                                    }

                                    using (MemoryMappedViewAccessor cryoVa = cryoMmf.CreateViewAccessor(0L, 0L, MemoryMappedFileAccess.Read))
                                    {
                                        ArkArchive cryoArchive = new ArkArchive(cryoVa, byteData.Length, _arkNameCache, _arkStringCache, _exclusivePropertyNameTree);

                                        var result = UpdateVivariumCreatureStatus(cryoArchive);
                                        result.Item1.Location = vivarium.Location;


                                        Objects.Add(result.Item1);
                                        Objects.Add(result.Item2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ;


            //Now parse out cryo creature data
            var cryoPodEntries = Objects.Where(WhereEmptyCryopodHasCustomItemDataBytesArrayBytes).ToList();

            nextObjectId = Objects.Count();

            if (cryoPodEntries != null && cryoPodEntries.Count() > 0)
            {
                foreach (var cryoPod in cryoPodEntries)
                {
                    var     byteList      = SelectCustomDataBytesArrayBytes(cryoPod);
                    sbyte[] sbyteValues   = byteList.Value.Cast <sbyte>().ToArray();
                    byte[]  cryoDataBytes = (byte[])(Array)sbyteValues;


                    using (MemoryMappedFile cryoMmf = MemoryMappedFile.CreateNew(null, cryoDataBytes.Length))
                    {
                        using (MemoryMappedViewStream stream = cryoMmf.CreateViewStream())
                        {
                            BinaryWriter writer = new BinaryWriter(stream);
                            writer.Write(cryoDataBytes);
                        }

                        using (MemoryMappedViewAccessor cryoVa = cryoMmf.CreateViewAccessor(0L, 0L, MemoryMappedFileAccess.Read))
                        {
                            ArkArchive cryoArchive = new ArkArchive(cryoVa, cryoDataBytes.Length, _arkNameCache, _arkStringCache, _exclusivePropertyNameTree);

                            var result            = UpdateCryoCreatureStatus(cryoArchive);
                            var ownerInventoryRef = cryoPod.GetProperty <PropertyObject>(_ownerInventory);

                            if (ownerInventoryRef != null && ownerInventoryRef.Value?.ObjectId != null)
                            {
                                var ownerContainerInventory = Objects.FirstOrDefault(o => o.ObjectId == ownerInventoryRef.Value.ObjectId);
                                if (ownerContainerInventory != null)
                                {
                                    var ownerContainer = Objects.FirstOrDefault(o => o.Properties.ContainsKey(_myInventoryComponent) && o.GetProperty <PropertyObject>(_myInventoryComponent).Value.ObjectId == ownerContainerInventory.ObjectId);
                                    if (ownerContainer != null && ownerContainer.Location != null)
                                    {
                                        result.Item1.Location = ownerContainer.Location;
                                    }
                                }
                            }

                            Objects.Add(result.Item1);
                            Objects.Add(result.Item2);
                        }
                    }
                }
                ;
            }

            return(true);

            bool WhereEmptyCryopodHasCustomItemDataBytesArrayBytes(GameObject o) => (o.ClassName.Name == "PrimalItem_WeaponEmptyCryopod_C" || o.ClassName.Name == "PrimalItem_WeaponEmptyCryopod_PE_C") &&
            o.GetProperty <PropertyArray>(_customItemData)?.Value[0] is StructPropertyList customProperties &&
            customProperties.GetProperty <PropertyStruct>(_customDataBytesIdentifier) is PropertyStruct customDataBytes &&
            customDataBytes.Value is StructPropertyList byteArrays &&
            byteArrays.GetProperty <PropertyArray>(_byteArraysIdentifier)?.Value.Count > 0 && byteArrays.GetProperty <PropertyArray>(_byteArraysIdentifier)?.Value[0] is StructPropertyList bytes &&
            bytes != null && bytes.GetProperty <PropertyArray>(_bytesIdentifier) is PropertyArray byteList &&
            byteList != null && byteList.Value.Count > 0;


            PropertyArray SelectCustomDataBytesArrayBytes(GameObject o) => ((StructPropertyList)((StructPropertyList)((StructPropertyList)o.GetProperty <PropertyArray>(_customItemData).Value[0]).GetProperty <PropertyStruct>(_customDataBytesIdentifier).Value).GetProperty <PropertyArray>(_byteArraysIdentifier).Value[0]).GetProperty <PropertyArray>(_bytesIdentifier);

            Tuple <GameObject, GameObject> UpdateCryoCreatureStatus(ArkArchive cryoArchive)
            {
                cryoArchive.GetBytes(4);

                nextObjectId++;
                var dino = new GameObject(cryoArchive)
                {
                    ObjectId = nextObjectId,
                    IsCryo   = true
                };

                nextObjectId++;
                var statusobject = new GameObject(cryoArchive)
                {
                    ObjectId = nextObjectId
                };

                dino.loadProperties(cryoArchive, new GameObject(), 0, null);



                var statusComponentRef = dino.GetProperty <PropertyObject>(_myCharacterStatusComponent);

                statusComponentRef.Value.ObjectId = statusobject.ObjectId;

                statusobject.loadProperties(cryoArchive, new GameObject(), 0, null);
                return(new Tuple <GameObject, GameObject>(dino, statusobject));
            }

            Tuple <GameObject, GameObject> UpdateVivariumCreatureStatus(ArkArchive vivariumArchive)
            {
                vivariumArchive.GetBytes(4);

                nextObjectId++;
                var dino = new GameObject(vivariumArchive)
                {
                    ObjectId   = nextObjectId,
                    IsVivarium = true
                };

                nextObjectId++;
                var statusobject = new GameObject(vivariumArchive)
                {
                    ObjectId = nextObjectId
                };

                dino.loadProperties(vivariumArchive, new GameObject(), 0, null);

                var statusComponentRef = dino.GetProperty <PropertyObject>(_myCharacterStatusComponent);

                statusComponentRef.Value.ObjectId = statusobject.ObjectId;

                statusobject.loadProperties(vivariumArchive, new GameObject(), 0, null);
                return(new Tuple <GameObject, GameObject>(dino, statusobject));
            }
        }
示例#9
0
 public int GetNumberOfQuestionsInQuiz(int quizId)
 {
     return(Objects
            .Count(q => q.QuizId == quizId));
 }
示例#10
0
 public override string ToString()
 {
     return($"{{ ObjectGroup name={base.Name}, numObjects={Objects.Count()} }}");
 }
示例#11
0
        public override void AddCard(Card card)
        {
            // By default, add the new card at the end
            int idx = Objects.Count;

            // If the run is empty or only contains joker cards, also add the new card at the end
            // otherwise
            if (Type == SpotType.RUN && Objects.Count(c => !c.IsJoker()) > 0)
            {
                // Find out the rank of the last card in the run
                int highestNonJokerIdx  = Objects.GetFirstCardIndex(Objects.Count - 1, false);
                var highestNonJokerRank = Objects[highestNonJokerIdx].Rank;
                var highestRank         = highestNonJokerRank + (Objects.Count - 1 - highestNonJokerIdx);
                if (highestNonJokerIdx == 0 && highestNonJokerRank == Card.CardRank.ACE)
                {
                    highestRank = (Card.CardRank)Objects.Count;
                }

                // If adding ACE after King is not possible, add ACE at beginning
                if (card.Rank == Card.CardRank.ACE &&
                    (highestRank < Card.CardRank.KING ||
                     (highestRank == Card.CardRank.ACE && !Objects[Objects.Count - 1].IsJoker())))
                {
                    idx = 0;
                }
                else if (card.IsJoker()) // Joker will be added at the end, if possible
                {
                    if (highestRank == Card.CardRank.ACE)
                    {
                        idx = 0;
                    }
                    else
                    {
                        idx = Objects.Count;
                    }
                }
                else // Any other case, the card will be sorted by rank
                {
                    for (int i = 0; i < Objects.Count; i++)
                    {
                        var rank = Objects[i].Rank;
                        if (Objects[i].IsJoker()) // Figure out the rank of the card which the joker is replacing
                        {
                            if (i == 0 && Objects.Count == 1)
                            {
                                // Joker is the only card in the run and the next card comes after the joker
                                idx = 1;
                                break;
                            }
                            rank = CardUtil.GetJokerRank(Objects, i);
                        }
                        else if (i == 0 && rank == Card.CardRank.ACE)
                        {
                            rank = (Card.CardRank) 1; // Although it's not actually a Joker
                        }
                        if (rank > card.Rank)
                        {
                            idx = i;
                            break;
                        }
                    }
                }
            }
            AddCard(card, idx);
        }
示例#12
0
        protected void PerformBasicAttack()
        {
            Enemy enemy = GetMostLeftUnit();

            if ((enemy != this && !_rabies) || Health <= 0)
            {
                Arena arena = (Arena)Objects.ObjFind <Arena>(0);
                arena.GiveInitiative();
                return;
            }

            if (_attackDialogue == null)
            {
                if (_skipTurn)
                {
                    var dialogueString = Strings.EnemySkipTurn
                                         .Replace("{0}", Name);
                    _attackDialogue = new Dialogue(new string[] { "" }, new string[] { dialogueString });
                    _skipTurn       = false;
                }
                else
                {
                    if (_rabies)
                    {
                        int objId = (int)(GameplayController.Random.NextDouble() * (float)Objects.Count <ArenaObj>());

                        ArenaObj obj = (ArenaObj)Objects.ObjFind <ArenaObj>(objId);

                        int dmg = Attack(obj);


                        var dialogueString = Strings.EnemyRabid
                                             .Replace("{0}", Name.ToLower())
                                             .Replace("{1}", obj.Name1.ToLower())
                                             .Replace("{2}", dmg.ToString());

                        _attackDialogue = new Dialogue(new string[] { "" }, new string[] { dialogueString });
                    }
                    else
                    {
                        int dmg = Attack((ArenaPlayer)Objects.ObjFind <ArenaPlayer>(0));

                        var dialogueString = Strings.EnemyAttack
                                             .Replace("{0}", Name)
                                             .Replace("{1}", dmg.ToString());

                        _attackDialogue = new Dialogue(new string[] { "" }, new string[] { dialogueString });
                    }
                }
            }
            else
            {
                if (_attackDialogue.Destroyed)
                {
                    _attackDialogue = null;
                    Arena arena = (Arena)Objects.ObjFind <Arena>(0);
                    arena.GiveInitiative();
                    _rabies = false;
                }
            }
        }