Exemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ModuleLibrary.Length != 0)
            {
                hash ^= ModuleLibrary.GetHashCode();
            }
            hash ^= components_.GetHashCode();
            hash ^= timerComponents_.GetHashCode();
            return(hash);
        }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        //set the starting weight at 0
        currentWeight = 0;

        //instantiate the weaponLibrary
        weaponLibrary = GetComponent<WeaponsLibrary>();
        moduleLibrary = GetComponent<ModuleLibrary>();

        //weaponPairList = new KeyValuePair<int, bool>[4] {{1, true}, {2, true}, {3, false}, {4, false}};
        weaponList = new string[4] {null, null, null, null};
        moduleList = new string[6] {null, null, null, null, null, null};

        //add 2 basic weapons for testing
        AddWeaponToInventory(-1, "StraightShooterBlue");
        AddWeaponToInventory(-1, "StraightShooterYellow");
        //RemoveWeaponFromInventory("StraightShooterBlue");

        //add a module for testing
        AddModuleToInventory(-1, "AccelThrusters");
        //RemoveModulesFromInventory("AccelThrusters");
    }
Exemplo n.º 3
0
        void IStreamListener.TweetCreateByAnyone(object sender, TweetReceivedEventArgs args)
        {
            if (!IsRunning)
            {
                return;
            }
            var tweet = args.Tweet;

            if (!Verification( ))
            {
                return;
            }
            if (tweet.CreatedBy.Id == Globals.Instance.User.Id)
            {
                return;
            }
            if (tweet.IsRetweet == true)
            {
                return;
            }

            var cases = new List <int>();

            for (int i = 0; i < reactor_category.Count; i++)
            {
                var category = reactor_category[i];
                var input    = reactor_input[i];

                // TODO: StringSetManager에서 Stringset간 참조에 대한 처리를 해주어야 합니다.
                if (input.StartsWith("__") && input.EndsWith("__"))
                {
                    var inputset  = StringSetsManager.GetStrings(input.Substring(2, input.Length - 4));
                    var loopbreak = false;
                    for (int j = 0; j < inputset.Length; j++)
                    {
                        var matchResult = IsMatch(category, inputset[j], tweet);
                        if (matchResult == TweetMatchResult.Match)
                        {
                            cases.Add(i);
                        }
                        else if (matchResult == TweetMatchResult.Expire)
                        {
                            loopbreak = true;
                            break;
                        }
                    }
                    if (loopbreak)
                    {
                        break;
                    }
                }
                else if (input.StartsWith("-__") && input.EndsWith("__"))
                {
                    var inputset = StringSetsManager.GetStrings(input.Substring(3, input.Length - 5));
                    for (int j = 0; j < inputset.Length; j++)
                    {
                        if (inputset[j].StartsWith("__") && inputset[j].EndsWith("__"))
                        {
                            var inputset_inner = StringSetsManager.GetStrings(inputset[j].Substring(2, inputset[j].Length - 4));
                            for (int k = 0; k < inputset_inner.Length; k++)
                            {
                                var matchResult = IsMatch(category, inputset_inner[k], tweet);
                                if (matchResult == TweetMatchResult.Match)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            var matchResult = IsMatch(category, inputset[j], tweet);
                            if (matchResult == TweetMatchResult.Match)
                            {
                                break;
                            }
                        }
                    }
                    if (IsCategoryMatch(category, tweet))
                    {
                        cases.Add(i);
                    }
                }
                else
                {
                    var matchResult = IsMatch(category, input, tweet);
                    if (matchResult == TweetMatchResult.Match)
                    {
                        cases.Add(i);
                    }
                    else if (matchResult == TweetMatchResult.Expire)
                    {
                        break;
                    }
                }
            }
            if (cases.Count > 0)
            {
                var    i    = _selector.Next(cases.Count);
                string @out = string.Empty;
                if (reactor_output[cases[i]].StartsWith("__") && reactor_output[cases[i]].EndsWith("__"))
                {
                    @out = StringSetsManager.GetRandomString(reactor_output[cases[i]].Substring(2, reactor_output[cases[i]].Length - 4));
                }
                else
                {
                    @out = reactor_output[cases[i]];
                }
                if (string.IsNullOrEmpty(@out))
                {
                    return;
                }
                var pString = ParseEscapeString(@out, tweet);
                if (pString.Flag)
                {
                    const int MaxDelay = 50;
                    System.Threading.Tasks.Task.Factory.StartNew(delegate
                    {
                        Thread.Sleep(_selector.Next(MaxDelay));                             // 나름의 랜덤 출력을 위한 결과물
                        var rjdcode = string.Format("rjd-{0}", tweet.Id);
                        var @var    = ModuleLibrary.GetValue(rjdcode);
                        if (@var == null || !( bool )@var)
                        {
                            ModuleLibrary.SetValue(rjdcode, true);
                            System.Threading.Tasks.Task.Factory.StartNew(delegate
                            {
                                Thread.Sleep(MaxDelay * 10);
                                ModuleLibrary.RemoveValue(rjdcode);
                            });

                            var result = Globals.Instance.User.PublishTweet(pString.String, new PublishTweetOptionalParameters()
                            {
                                InReplyToTweetId = pString.Id
                            });
                            Log.Print(this.Name, "Send tweet [{0}]", result.Text);

                            if (ExpireUsers.ContainsKey(tweet.CreatedBy.Id))
                            {
                                ExpireUsers[tweet.CreatedBy.Id] = new TimeSet(DateTime.Now);
                            }
                            else
                            {
                                ExpireUsers.Add(tweet.CreatedBy.Id, new TimeSet(DateTime.Now));
                            }
                        }
                    });
                }
            }
        }