Example #1
0
        private IEnumerable <ApiEvent> ConvertEvent(Reputation e)
        {
            yield return(new ApiEvent("setCommanderReputationMajorFaction")
            {
                Timestamp = e.Timestamp,
                EventData = new Dictionary <string, object>()
                {
                    { "majorfactionName", nameof(e.Empire) },
                    { "majorfactionReputation", System.Convert.ToSingle(e.Empire) / 100.0f },
                }
            });

            yield return(new ApiEvent("setCommanderReputationMajorFaction")
            {
                Timestamp = e.Timestamp,
                EventData = new Dictionary <string, object>()
                {
                    { "majorfactionName", nameof(e.Alliance) },
                    { "majorfactionReputation", System.Convert.ToSingle(e.Alliance) / 100.0f },
                }
            });

            yield return(new ApiEvent("setCommanderReputationMajorFaction")
            {
                Timestamp = e.Timestamp,
                EventData = new Dictionary <string, object>()
                {
                    { "majorfactionName", nameof(e.Federation) },
                    { "majorfactionReputation", System.Convert.ToSingle(e.Federation) / 100.0f },
                }
            });
        }
        public async Task <ReputationResponse> UpdateAsync(int id, Reputation reputation)
        {
            var existingReputation = await _reputationRepository.FindByIdAsync(id);

            if (existingReputation == null)
            {
                return(new ReputationResponse("Reputation not found."));
            }

            var existingPersonnel = await _personnelRepository.FindByIdAsync(reputation.PersonnelId);

            if (existingPersonnel == null)
            {
                return(new ReputationResponse("Invalid personnel."));
            }

            existingReputation.Points      = reputation.Points;
            existingReputation.PersonnelId = reputation.PersonnelId;

            try
            {
                _reputationRepository.Update(existingReputation);
                await _unitOfWork.CompleteAsync();

                return(new ReputationResponse(existingReputation));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new ReputationResponse($"An error occurred when updating the reputation: {ex.Message}"));
            }
        }
        private ReputationViewModel GetReputationViewModel(Reputation reputation)
        {
            var maxValue = _reputationService.GetMaxAmount();

            var minValue = _reputationService.GetMinAmount();

            var threshold = _reputationService.GetThresholdValue();

            var test = ((((float)reputation.Peasants - (float)minValue) /
                         ((float)maxValue - (float)minValue)) * 100f);

            return(new ReputationViewModel()
            {
                MaxValue = maxValue,
                MinValue = minValue,
                Threshold = threshold,
                Peasants = reputation.Peasants,
                Church = reputation.Church,
                Bandits = reputation.Bandits,
                Nobles = reputation.Nobles,
                PeasantsInPercent = (((float)reputation.Peasants - (float)minValue) /
                                     ((float)maxValue - (float)minValue)) * 100f,
                ChurchInPercent = (((float)reputation.Church - (float)minValue) /
                                   ((float)maxValue - (float)minValue)) * 100f,
                BanditsInPercent = (((float)reputation.Bandits - (float)minValue) /
                                    ((float)maxValue - (float)minValue)) * 100f,
                NoblesInPercent = (((float)reputation.Nobles - (float)minValue) /
                                   ((float)maxValue - (float)minValue)) * 100f
            });
        }
    public PlayerData(List<ScreenObject> screens, Color col, List<StaffMember> staff, List<FilmShowing> films, int coins, int day, int popcorn, List<OtherObject> others, bool redCarpet, bool marble, Reputation rep, int boxOffice, FoodArea fa, bool[] poster, Options opt)
    {
        theScreens = screens.ToArray();
        carpetColour = new float[4] { col.r, col.g, col.b, col.a };

        List<SaveableStaff> staffList = new List<SaveableStaff>();

        for (int i = 0; i < staff.Count; i++)
        {
            SaveableStaff s = new SaveableStaff(staff[i]);
            staffList.Add(s);
        }

        staffMembers = staffList.ToArray();
        filmShowings = films.ToArray();
        totalCoins = coins;
        currentDay = day;
        numPopcorn = popcorn;
        otherObjects = others.ToArray();
        hasRedCarpet = redCarpet;
        marbleFloor = marble;
        reputation = rep;
        boxOfficeLevel = boxOffice;
        posters = poster;
        foodArea = fa;
        options = opt;
    }
Example #5
0
    public static void offsetReputation(NetworkPlayer player, int amount)
    {
        int num = 0;

        while (num < NetworkUserList.users.Count)
        {
            if (NetworkUserList.users[num].player != player)
            {
                num++;
            }
            else
            {
                NetworkHandler.tool.networkView.RPC("setReputation", RPCMode.All, new object[] { player, NetworkUserList.users[num].reputation + amount });
                if (amount >= 0)
                {
                    NetworkManager.error(string.Concat("+", amount, " Reputation"), Reputation.getIcon(NetworkUserList.users[num].reputation), player);
                }
                else
                {
                    NetworkManager.error(string.Concat(amount, " Reputation"), Reputation.getIcon(NetworkUserList.users[num].reputation), player);
                }
                Savedata.saveReputation(NetworkUserList.users[num].id, NetworkUserList.users[num].reputation.ToString());
                break;
            }
        }
    }
Example #6
0
    public void Init(CharacterRoster characterRoster, Map map)
    {
        money = new Money();
        money.Increment(10.00M);
        money.textRefrence = MoneyText;

        reputation = new Reputation();
        reputation.textRefrence = ReputationText;


        StatsButton.StoredCommand = new ChangeEndOfDayState(this, _Stats);
        _Stats.ButtonForState     = StatsButton;


        MapButton.StoredCommand = new ChangeEndOfDayState(this, _EditMap);
        _EditMap.ButtonForState = MapButton;


        _Supply.InitState(money, map);
        OrderSupplyButton.StoredCommand = new ChangeEndOfDayState(this, _Supply);
        _Supply.ButtonForState          = OrderSupplyButton;
        startNextDay += _Supply.OnStartNextDay;

        _Schedule.InitState(money, characterRoster);
        scheduleButton.StoredCommand = new ChangeEndOfDayState(this, _Schedule);
        _Schedule.ButtonForState     = scheduleButton;
        startNextDay += _Schedule.OnStartNextDay;

        _curState = _Stats;
    }
Example #7
0
        internal static Reputation ReputationViewModelToReputation(ReputationViewModel reputation)
        {
            if (reputation == null)
            {
                return(null);
            }

            Reputation result = new Reputation
            {
                Id      = reputation.Id,
                Name    = reputation.Name,
                Markers = new ReputationMarker[reputation.Markers.Count]
            };

            for (int markerIndex = 0; markerIndex < result.Markers.Length; markerIndex++)
            {
                var marker = reputation.Markers[markerIndex];

                var resultMarker = result.Markers[markerIndex] = new ReputationMarker();

                resultMarker.Name  = marker.Name;
                resultMarker.Value = marker.Value;
            }

            return(result);
        }
Example #8
0
 private void CloseAllStreams()
 {
     _logger.Info($"Closing streams");
     if(!(Time is null))
     {
         Time.RemoveCallback(TimeTag);
         Time.Remove();
         _logger.Info($"Time Closed");
     }
     if(!(Science is null))
     {
         Science.RemoveCallback(ScienceTag);
         Science.Remove();
         _logger.Info($"Science Closed");
     }
     if(!(Funds is null))
     {
         Funds.RemoveCallback(FundsTag);
         Funds.Remove();
         _logger.Info($"Funds Closed");
     }
     if(!(Reputation is null))
     {
         Reputation.RemoveCallback(ReputationTag);
         Reputation.Remove();
         _logger.Info($"Reputation Closed");
     }
     if(!(GameScene is null))
     {
         GameScene.RemoveCallback(GameSceneTag);
         GameScene.Remove();
         _logger.Info($"GameScene Closed");
     }
 }
Example #9
0
 void Start()
 {
     repu          = GameObject.FindGameObjectWithTag("GameManager").GetComponent <Reputation>();
     money         = GameObject.FindGameObjectWithTag("GameManager").GetComponent <MoneyCounter>();
     passangerData = GameObject.FindGameObjectWithTag("Notepad").GetComponent <StorePassangerData>();
     currentState  = driverState.waiting;
 }
Example #10
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity <Personnel>().ToTable("Personnels");
            builder.Entity <Personnel>().HasKey(p => p.Id);
            builder.Entity <Personnel>().Property(p => p.Id).IsRequired();
            builder.Entity <Personnel>().Property(p => p.Name).IsRequired().HasMaxLength(50);
            builder.Entity <Personnel>().Property(p => p.Surname).IsRequired().HasMaxLength(50);
            builder.Entity <Personnel>().HasOne <Reputation>(p => p.Reputation).WithOne(bp => bp.Personnel).HasForeignKey <Reputation>(bp => bp.PersonnelId);

            var entry = new Personnel {
                Id = 1, Name = "Sam", Surname = "Davidson"
            };

            builder.Entity <Personnel>().HasData
            (
                entry
            );

            builder.Entity <Reputation>().ToTable("Reputations");
            builder.Entity <Reputation>().HasKey(p => p.Id);
            builder.Entity <Reputation>().Property(p => p.Id).IsRequired();
            builder.Entity <Reputation>().Property(p => p.PersonnelId).IsRequired();
            builder.Entity <Reputation>().Property(p => p.Points).IsRequired();

            var point = new Reputation {
                Id = 1, PersonnelId = entry.Id, Points = 0
            };

            builder.Entity <Reputation>().HasData
            (
                point
            );
        }
    // Update is called once per frame
    void Update()
    {
        레벨.text = "레벨 : " + level.ToString("0");;

        경험치.text = "경험치 : " + exp.ToString("0") + "/" + nextexp[level];;

        평판.text = "평판 : " + Reputation.ToString("0") + "점";
    }
Example #12
0
 public Villager(string name, Reputation reputation, List <string> prompts)
 {
     Name                  = name;
     Attributes            = AttributeFactory.GetInstance("Villager");
     Reputation            = reputation;
     Prompts               = prompts;
     InteractionTriggered += OnInteractionTriggered;
 }
Example #13
0
 public Villager(string name, Reputation reputation, List<string> prompts)
 {
     Name = name;
     Attributes = AttributeFactory.GetInstance("Villager");
     Reputation = reputation;
     Prompts = prompts;
     InteractionTriggered += OnInteractionTriggered;
 }
 internal ReputationEvent InvokeEvent(ReputationEvent arg)
 {
     if (_api.ValidateEvent(arg))
     {
         Reputation?.Invoke(_api, arg);
     }
     return(arg);
 }
Example #15
0
        public int addReputation(Reputation rep)
        {
            object obj2 = (" " + "insert into  pt_reputation (") + " requtBh,requtBgbh, dwId, productMc, makeNl,serviceSh,reputSh,productJc,procedtSy,materialFs, " + " qualityFS , projectFS , tryFS , prjDeptFS , appraise ,appraJg ,manager, appreDate ,tablePeo ) ";
            object obj3 = string.Concat(new object[] { obj2, " values ('", rep.RequtBh, "' , '", rep.RequtBgbh, "',", rep.DwId, " , '", rep.ProductMc, "' , '", rep.MakeNl, "','", rep.ServiceSh, "' ,'" });
            object obj4 = string.Concat(new object[] { obj3, rep.ReputSh, "' ,'", rep.ProductJc, "' ,'", rep.ProcedtSy, "' , ", rep.MaterialFs, " , ", rep.QualityFS, " , " });
            string str2 = string.Concat(new object[] { obj4, rep.ProjectFS, " , ", rep.TryFS, " , ", rep.PrjDeptFS, " , '", rep.Appraise, "' , ", rep.AppraJg, " , '" });

            return(publicDbOpClass.ExecSqlString(str2 + rep.Manager + "' , '" + rep.AppreDate + "' , '" + rep.TablePeo + "')"));
        }
Example #16
0
 /// <summary>
 /// Lets player know they are at war with a certain faction.
 /// </summary>
 public static void SendSetAtWar(IPacketReceiver client, Reputation rep)
 {
     using (RealmPacketOut packet = new RealmPacketOut(RealmServerOpCode.SMSG_SET_FACTION_ATWAR, 5))
     {
         packet.Write((int)rep.Faction.ReputationIndex);
         packet.Write((byte)rep.Flags);
         client.Send(packet, false);
     }
 }
Example #17
0
        public ReputationServices()
        {
            _reputation          = new Reputation();
            _reputation.Peasants = 0;
            _reputation.Church   = 0;
            _reputation.Bandits  = 0;
            _reputation.Nobles   = 0;

            CorrectReputation();
        }
Example #18
0
 public void SetDefaultReputation()
 {
     _reputation = new Reputation
     {
         Peasants = 0,
         Church   = 0,
         Bandits  = 0,
         Nobles   = 0
     };
 }
Example #19
0
        public ActionResult TakeRep(string target)
        {
            Reputation rep = new Reputation()
            {
                Amount   = -1,
                Receiver = repo.Get(target),
                Sender   = repo.Get(Session["CurrentUser-Username"].ToString())
            };

            repRepo.Add(rep);
            return(new EmptyResult());
        }
Example #20
0
        public int UpReputation(Reputation rep, int reputID)
        {
            object obj2 = ((" " + " update pt_reputation ") + " set requtBh = '" + rep.RequtBh + "',") + " requtBgbh = '" + rep.RequtBgbh + "',";
            object obj3 = (((((string.Concat(new object[] { obj2, " dwId = ", rep.DwId, "," }) + " productMc = '" + rep.ProductMc + "',") + " makeNl = '" + rep.MakeNl + "',") + " serviceSh = '" + rep.ServiceSh + "',") + " reputSh ='" + rep.ReputSh + "',") + " productJc = '" + rep.ProductJc + "',") + " procedtSy = '" + rep.ProcedtSy + "',";
            object obj4 = string.Concat(new object[] { obj3, " materialFs =", rep.MaterialFs, "," });
            object obj5 = string.Concat(new object[] { obj4, " qualityFS = ", rep.QualityFS, " ," });
            object obj6 = string.Concat(new object[] { obj5, " projectFS = ", rep.ProjectFS, "," });
            object obj7 = string.Concat(new object[] { obj6, " tryFS=", rep.TryFS, "," });
            object obj8 = string.Concat(new object[] { obj7, " prjDeptFS = ", rep.PrjDeptFS, "," }) + " appraise = '" + rep.Appraise + "',";

            return(publicDbOpClass.ExecSqlString((((string.Concat(new object[] { obj8, " appraJg = ", rep.AppraJg, "," }) + " manager = '" + rep.Manager + "',") + " appreDate = '" + rep.AppreDate + "',") + " tablePeo = '" + rep.TablePeo + "'") + " where reputID = " + reputID));
        }
Example #21
0
        public ReputationViewItem(Reputation reputation)
        {
            Reputation = reputation;

            Text = reputation.Username;
            SubItems.AddRange(new[]
            {
                reputation.Number.ToString("+#;-#;0"),
                reputation.Comment,
                reputation.Time
            });
        }
Example #22
0
        /// <summary>
        /// Sends a reputation update.
        /// </summary>
        public static void SendReputationStandingUpdate(IPacketReceiver client, Reputation rep)
        {
            using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_SET_FACTION_STANDING, 16))
            {
                packet.Write(0f);                 // Refer-A-Friend bonus reputation
                packet.Write((byte)0);
                packet.Write(1);                  // count (we only ever send 1)
                packet.Write((uint)rep.Faction.ReputationIndex);
                packet.Write(rep.Value);

                client.Send(packet);
            }
        }
Example #23
0
 /// <summary>Sends a reputation update.</summary>
 public static void SendReputationStandingUpdate(IPacketReceiver client, Reputation rep)
 {
     using (RealmPacketOut packet =
                new RealmPacketOut(RealmServerOpCode.SMSG_SET_FACTION_STANDING, 16))
     {
         packet.Write(0.0f);
         packet.Write((byte)0);
         packet.Write(1);
         packet.Write((uint)rep.Faction.ReputationIndex);
         packet.Write(rep.Value);
         client.Send(packet, false);
     }
 }
Example #24
0
        public void AddReputation(Reputation additive)
        {
            UnderThreshold beforeSumm = GetMaxUnderThreshold();

            int[] thresholdArr = GetThresholCorrectingdArr(beforeSumm);

            AddPeasants(additive.Peasants, thresholdArr[0]);
            AddChurch(additive.Church, thresholdArr[1]);
            AddBandits(additive.Bandits, thresholdArr[2]);
            AddNobles(additive.Nobles, thresholdArr[3]);

            CorrectReputation();
        }
Example #25
0
    public Faction()
    {
        Religions         = new Dictionary <string, int>();
        EntitiesWithFluff = new List <Entity>();

        Name = FactionTemplateLoader.Instance.GenerateFactionName();
        GeneratePopulation();
        CreateLeader();

        FactionReputation = new Reputation(EntityGroupType.Faction, Name);

        WorldData.Instance.EntityGroupRelationships.Add(Name, FactionReputation);
    }
Example #26
0
    public Faction(FactionSdo sdo)
    {
        Religions         = new Dictionary <string, int>();
        EntitiesWithFluff = new List <Entity>();

        PopType           = sdo.PopType;
        FactionReputation = sdo.FactionReputation;
        Citizens          = new List <Entity>();
        EntitiesWithFluff = new List <Entity>();
        Name       = sdo.Name;
        Population = sdo.Population;
        Leader     = EntitySdo.ConvertToEntity(sdo.Leader);

        if (Leader == null)
        {
            Debug.Log($@"Leader missing for faction {Name}");
        }

        foreach (var id in sdo.CitizenIds)
        {
            if (!WorldData.Instance.Entities.ContainsKey(id))
            {
                continue;
            }

            var citizen = WorldData.Instance.Entities[id];
            citizen.Faction = this;
            Citizens.Add(citizen);
        }

        foreach (var id in sdo.EntitiesWithFluffIds)
        {
            if (!WorldData.Instance.Entities.ContainsKey(id))
            {
                continue;
            }

            var entity = WorldData.Instance.Entities[id];
            EntitiesWithFluff.Add(entity);
        }

        if (Leader != null && !WorldData.Instance.Entities.ContainsKey(Leader.Id))
        {
            WorldData.Instance.Entities[Leader.Id] = Leader;
        }

        if (!EntitiesWithFluff.Contains(Leader))
        {
            EntitiesWithFluff.Add(Leader);
        }
    }
Example #27
0
    /*Function called from the EventManager.cs using the attackTargetEVT delegate event
     * Determines if this ship is allowed to attack a target and sets hostility */
    private void AttackTarget(EVTData data_)
    {
        //Does nothing if this ship isn't player controlled. Can't have the player control enemy ships now can we?
        if (GetComponent <HealthTracker>().reputationStanding != Reputation.PlayerControlled)
        {
            return;
        }

        //Does nothing if this object is not selected
        if (!MouseData.objectSelected.Contains(this.gameObject))
        {
            return;
        }

        this.targetObj = data_.objectSelected.objectSelected;

        //Can't attack object's unless certain parameters are met
        if (this.targetObj.GetComponent <HealthTracker>() != null && !this.weaponless)
        {
            Reputation thisShip  = this.gameObject.GetComponent <HealthTracker>().reputationStanding;
            Reputation otherShip = this.targetObj.GetComponent <HealthTracker>().reputationStanding;

            //If this ship is non-hostile and non-chaotic, it won't attack other non-hostile/non-chaotic ships
            if ((thisShip != Reputation.Hostile && thisShip != Reputation.Chaotic) &&
                (otherShip != Reputation.Hostile && otherShip != Reputation.Chaotic))
            {
                this.hostile = false;
            }
            //If this ship is hostile, it won't attack other hostile ships
            else if (thisShip == Reputation.Hostile && otherShip == Reputation.Hostile)
            {
                this.hostile = false;
            }
            //If this ship is chaotic, it won't attack other chaotic ships
            else if (thisShip == Reputation.Chaotic && otherShip == Reputation.Chaotic)
            {
                this.hostile = false;
            }
            //Otherwise the ships are enemies and will attack
            else
            {
                this.hostile = true;
            }
        }
        else
        {
            this.hostile = false;
        }

        this.movePos = new Vector3(1, 1, 1);
    }
Example #28
0
        public void TestInitialReputations()
        {
            Setup.EnsureDBSetup();
            FactionMgr.Initialize();

            var stormWind = FactionMgr.Get(FactionId.Stormwind);
            var bootyBay  = FactionMgr.Get(FactionId.BootyBay);

            Assert.IsNotNull(bootyBay);

            var reputation = new Reputation(new ReputationRecord(), bootyBay, 1000, ReputationFlags.None);

            Asser.FlatNotSet(reputation.Flags, ReputationFlags.AtWar);
        }
Example #29
0
        /// <summary>
        /// 获取最近的NPC并接近和他对话
        /// </summary>
        private void getNPC()
        {
            Obj_NPC        TargetNpc   = null;
            List <Obj_NPC> npcList     = new List <Obj_NPC>();
            float          minDistance = float.PositiveInfinity;
            Vector3        mainPlayerPos;

            mainPlayerPos = Singleton <ObjManager> .GetInstance().MainPlayer.Position;

            foreach (string strName in Singleton <ObjManager> .GetInstance().ObjPools.Keys)
            {//遍历场景中的npc
                Obj_Character objChar = Singleton <ObjManager> .GetInstance().ObjPools[strName] as Obj_Character;

                if (null == objChar)
                {
                    continue;
                }
                TargetNpc = objChar as Obj_NPC;
                if (TargetNpc == null)
                {
                    continue;
                }
                if (Reputation.IsFriend(TargetNpc))
                {//如果是友好NPC则添加进npc列表
                    npcList.Add(TargetNpc);
                }
            }
            for (int i = 0; i < npcList.Count; i++)
            {//比较距离,得到最近的那个npc
                float curDistance = Vector3.Distance(mainPlayerPos, npcList[i].Position);
                if (curDistance < minDistance)
                {
                    minDistance = curDistance;
                    TargetNpc   = npcList[i];
                }
            }

            if (TargetNpc == null)
            {
                return;
            }

            if (null != Singleton <ObjManager> .GetInstance().MainPlayer)
            {
                Singleton <ObjManager> .GetInstance().MainPlayer.SelectTarget = TargetNpc;

                Singleton <ObjManager> .GetInstance().MainPlayer.OnSelectTarget(TargetNpc.gameObject);
            }
        }
Example #30
0
        public void Drop(Reputation rep)
        {
            using (var context = new BoardContext())
            {
                context.Database.Log = Console.WriteLine;

                var dRep = context.Reputations.Single(u => u.Id == rep.Id);
                if (dRep != null)
                {
                    context.Reputations.Remove(dRep);
                }

                context.SaveChanges();
            }
        }
Example #31
0
    // 寻路找怪处理
    void FindEnamyTick()
    {
        if (m_bNotEnamyNpcFlag != 0)
        {
            return;
        }
        //如果有目标名字则寻找该目标,进行交互
        if (m_Path.AutoSearchTargetName != "")
        {
            Obj_Character obj = Singleton <ObjManager> .GetInstance().FindObjCharacterInSceneByName(m_Path.AutoSearchTargetName);

            if (obj && obj.ObjType == Games.GlobeDefine.GameDefine_Globe.OBJ_TYPE.OBJ_NPC)
            {
                Obj_NPC objNpc = obj as Obj_NPC;
                //根据目标NPC的势力确认是对话还是攻击
                if (Reputation.IsEnemy(objNpc) || Reputation.IsNeutral(objNpc))
                {
                    Singleton <ObjManager> .GetInstance().MainPlayer.StopMove();

                    m_Path.AutoSearchPosCache.Clear();
                    m_Path.ResetPath();
                    IsAutoSearching = false;
                    m_EndPointCache.Clean();

                    //如果是地方NPC,则开始攻击
                    Singleton <ObjManager> .GetInstance().MainPlayer.OnSelectTarget(objNpc.gameObject);

                    Singleton <ObjManager> .GetInstance().MainPlayer.OnEnterCombat(objNpc.GetComponent <Obj_Character>());

                    m_bNotEnamyNpcFlag = 1;

                    // 杀怪任务寻路结束,如果没在自动战斗状态,则进入自动战斗
                    Obj_MainPlayer mainPlayer = Singleton <ObjManager> .GetInstance().MainPlayer;

                    if (null != mainPlayer && !mainPlayer.GetAutoCombatState() && Singleton <ObjManager> .Instance.MainPlayer.IsOpenCabalAuto)
                    {
                        mainPlayer.EnterAutoCombat();
                        GameManager.gameManager.MissionManager.MissionAutoCombat = true;
                    }
                }
                else
                {
                    m_bNotEnamyNpcFlag = 2;
                    return;
                }
            }
        }
    }
Example #32
0
        public static Caravan CaravanArrival(Caravan car)
        {
            car.current_step = null;
            car.location     = null;
            car.directions   = null;

            using (var db = new MinionWarsEntities())
            {
                Camp source      = db.Camp.Find(car.source_id);
                Camp destination = db.Camp.Find(car.destination_id);

                source.richness++;
                destination.richness++;

                if (source.owner_id != null)
                {
                    Reputation        rep  = null;
                    List <Reputation> list = db.Reputation.Where(x => x.user_id == source.owner_id && x.camp_id == destination.id).ToList();
                    if (list.Count > 0)
                    {
                        rep = list.First();
                        rep.value++;

                        db.Reputation.Attach(rep);
                        db.Entry(rep).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        rep       = new Reputation();
                        rep.value = 1;

                        db.Reputation.Add(rep);
                    }
                }

                db.Caravan.Attach(car);
                db.Entry(car).State = System.Data.Entity.EntityState.Modified;
                db.Camp.Attach(source);
                db.Entry(source).State = System.Data.Entity.EntityState.Modified;
                db.Camp.Attach(destination);
                db.Entry(destination).State = System.Data.Entity.EntityState.Modified;

                db.SaveChanges();
            }

            return(car);
        }
Example #33
0
        internal static ReputationViewModel ReputationToReputationViewModel(Reputation reputation)
        {
            if (reputation == null)
            {
                return null;
            }

            ReputationViewModel result = new ReputationViewModel
            {
                Id = reputation.Id,
                Name = reputation.Name
            };

            foreach (var marker in reputation.Markers)
            {
                result.AddMarker(new ReputationMarkerViewModel { Name = marker.Name, Value = marker.Value });
            }

            return result;
        }
            // This walks through fullHashCache, and if it finds the hash, this changes that entry to include the new reputation value
            private void UpdateFullHashCache(byte[] hash, Reputation newReputation)
            {
                Reputation reputationFromCache = Reputation.None;
                for (int index = 0; index < fullHashCache.Count; index++)
                {
                    // Compare the byte array of the hash
                    if (true == fullHashCache[index].hash.SequenceEqual(hash))
                    {
                        // There was a match. Extract the stored reputation and delete the entry
                        reputationFromCache = fullHashCache[index].reputation;
                        fullHashCache.RemoveAt(index);
                        break;
                    }
                }

                // Create a new entry with the merged reputation value
                byte[] newHash = (byte[])hash.Clone();
                fullHashCache.Add(new HashAndReputation(newHash, (reputationFromCache | newReputation)));
            }
            // Returns true if there is a match to a cached list (e.g. the entry is malicious)
            private static void CompareEntry(ref Reputation result, byte[] compareHash)
            {
                // The following code uses the quickLookupCache
                UInt32 hash = GetLittleEndianUintFromByteArray(ref compareHash);
                if (quickLookupCache.ContainsKey(hash))
                {
                    result = quickLookupCache[hash];
                }
                else
                {
                    result = Reputation.None;
                }

                /*
                 * The following code uses the master lists. This code is much slower than using the quickLookupCache,
                 * but it is compatible with whitelists and hash prefixes that aren't 32 bits.
                 * To use this code you'll need to change this method signature to include ref MasterList[] masterLists
                {
                    // For each master list (e.g. malware blacklist)
                    // Shortcut: Skipping checks on whitelists.
                    for (int index = 0; masterLists.Length > index; index += 2)
                    {
                        if (0 != (result & (Reputation)(0x1 << (index / 2))))
                        {
                            continue;
                        }

                        // Iterate through all chunks in the list
                        foreach (KeyValuePair<uint, Chunk> kvp in masterLists[index].e)
                        {
                            // In each chunk, check for a match
                            uint compareHashNumber = GetLittleEndianUintFromByteArray(ref compareHash);
                            if (true == kvp.Value.e.ContainsKey(compareHashNumber))
                            {
                                result |= (Reputation)(0x1 << (index / 2));
                                break;
                            }
                        }
                    }
                }
                 * */
            }
Example #36
0
 void Awake()
 {
     name = gameObject.name;
     reputation = GetComponent<Reputation>();
     position = transform.position;
     personSprite = GetComponent<PersonSprite>();
     schedule = GetComponent<Schedule>();
     if(gameObject.GetComponent<Collider>()){
         currentBound = gameObject.GetComponent<Collider>().bounds;
     }
     personMovement = GetComponent<PersonMovement>();
 }
Example #37
0
 public XamlReputation(Reputation reputation)
 {
     this.Id = reputation.Id;
     this.Name = reputation.Name;
     this.Markers.CopyFrom(reputation.Markers, mark => new XamlReputationMarker(mark));
 }
            // If the hash exists in the fullHashCache, then this returns true and the associated reputation
            // If it does not exist, then it returns false and Reputation.None
            private bool IsEntryInFullHashCache(byte[] hash, out Reputation reputationFromCache)
            {
                bool fFound = false;
                reputationFromCache = Reputation.None;

                for (int index = 0; index < fullHashCache.Count; index++)
                {
                    // Compare the byte array of the hash
                    if (true == fullHashCache[index].hash.SequenceEqual(hash))
                    {
                        // There was a match. Extract the stored reputation and delete the entry
                        reputationFromCache = fullHashCache[index].reputation;
                        fFound = true;
                        break;
                    }
                }

                return fFound;
            }
 public HashAndReputation(byte[] newHash, Reputation newReputation)
 {
     hash = newHash; reputation = newReputation;
 }
Example #40
0
        internal static Reputation ReputationViewModelToReputation(ReputationViewModel reputation)
        {
            if (reputation == null)
            {
                return null;
            }

            Reputation result = new Reputation
            {
                Id = reputation.Id,
                Name = reputation.Name,
                Markers = new ReputationMarker[reputation.Markers.Count]
            };

            for (int markerIndex = 0; markerIndex < result.Markers.Length; markerIndex++)
            {
                var marker = reputation.Markers[markerIndex];

                var resultMarker = result.Markers[markerIndex] = new ReputationMarker();

                resultMarker.Name = marker.Name;
                resultMarker.Value = marker.Value;
            }

            return result;
        }