public ViewModelEntity(IProtoEntity entity, bool defaultIsEnabled = false) { Entity = entity; Name = entity.Name; Id = entity.Id; isEnabled = defaultIsEnabled; }
public StatEntry(IProtoEntity source, StatName statName, double value, double percent) { this.Source = source; this.StatName = statName; this.Value = value; this.Percent = percent; }
private StatsSources AddOrUpdate( IProtoEntity source, StatName statName, double value, double percent) { this.list ??= new List <StatEntry>(); for (var index = 0; index < this.list.Count; index++) { var entry = this.list[index]; if (entry.StatName == statName && entry.Source == source) { // found existing entry - update it entry.Value += value; entry.Percent += percent; this.list[index] = entry; return(this); } } // create new entry this.list.Add(new StatEntry(source, statName, value, percent)); return(this); }
public static ITextureResource GetOriginalIcon(IProtoEntity protoEntity) { switch (protoEntity) { case IProtoItem protoItem: { return(protoItem.Icon); } case IProtoCharacterMob protoCharacterMob: { return(protoCharacterMob.Icon); } case TechGroup techGroup: { return(techGroup.Icon); } default: { return(null); } } }
public BaseStatsDictionary AddPercent(IProtoEntity source, StatName statName, double percent) { if (percent == 0) { return(this); } var multiplier = percent / 100d; // simply sum multipliers (like values) if (multiplier == 0) { return(this); } StatsSources.RegisterPercent(ref this.sources, source, statName, percent); if (this.Multipliers.TryGetValue(statName, out var currentMultiplier)) { // simply sum with existing value multiplier += currentMultiplier; } else { // non-existing multiplier - add base multiplier (one) multiplier += 1; } this.ValidateIsNotReadOnly(); this.Multipliers[statName] = multiplier; return(this); }
public ViewDataEntryFishCompletionist( IProtoEntity prototype, ActionCommandWithParameter commandClaimReward) : base(prototype, commandClaimReward) { }
public DamageSourceRemoteEntry(IProtoEntity protoEntity, string name, string clanTag, float fraction) { this.ProtoEntity = protoEntity; this.Name = name; this.ClanTag = clanTag; this.Fraction = fraction; }
public ViewModelEntity(IProtoEntity entity) { Entity = entity; Name = entity.Name; Id = entity.Id; isEnabled = false; }
public static RecipeViewModel SelectBasicRecipe([NotNull] IProtoEntity entity) { if (entity is Recipe recipe) { switch (recipe.RecipeType) { case RecipeType.Hand: return(new HandCraftingRecipeViewModel(recipe)); case RecipeType.StationCrafting: return(new StationCraftingRecipeViewModel(recipe)); case RecipeType.Manufacturing: return(new ManufacturingRecipeViewModel(recipe)); case RecipeType.ManufacturingByproduct: return(new ManufacturingByproductRecipeViewModel(recipe)); default: Api.Logger.Error("CNEI: Can not recognize recipe type for " + recipe); return(new BasicRecipeViewModel(recipe)); } } Api.Logger.Error("CNEI: Entity " + entity + " is not a recipe, can not proceed."); throw new ArgumentException(); }
public static void RegisterValue( ref StatsSources stats, IProtoEntity source, StatName statName, double value) { stats = stats.AddOrUpdate(source, statName, value, percent: 0); }
public static void RegisterPercent( ref StatsSources stats, IProtoEntity source, StatName statName, double percent) { stats = stats.AddOrUpdate(source, statName, value: 0, percent: percent); }
internal ViewDataEntryCompletionist( IProtoEntity prototype, ActionCommandWithParameter commandClaimReward) { this.Prototype = prototype; this.CommandClaimReward = commandClaimReward; this.State = ViewModelWindowCompletionist.CompletionistEntryState.Undiscovered; this.RefreshIconTexture(); }
public void ClientSetIconSource(IStaticWorldObject worldObjectCrate, IProtoEntity iconSource) { if (GetPublicState(worldObjectCrate).IconSource == iconSource) { return; } this.CallServer(_ => _.ServerRemote_SetIconSource(worldObjectCrate, iconSource)); }
public ViewModelDamageSource( IProtoEntity protoEntity, string name, int percent) : base(isAutoDisposeFields: false) { this.name = name; this.protoEntity = protoEntity; this.Percent = percent; }
private TaskCompleteCompletionistEntry( IProtoEntity entryProtoEntity, CompletionistPageName completionistPage, bool isRewardClaimRequired) : base(description: null) { this.EntryProtoEntity = entryProtoEntity; this.CompletionistPage = completionistPage; this.IsRewardClaimRequired = isRewardClaimRequired; }
public ProtoEntityViewModel([NotNull] IProtoEntity entity) { ProtoEntity = entity; Title = entity.Name == "" ? entity.GetType().Name : entity.Name; TitleLower = entity.Name.ToLower(); Type = entity.Id; TypeLower = entity.Id.ToLower(); RecipeVMWrappersList = new List <RecipeViewModelComboBoxWraper>(); UsageVMWrappersList = new List <RecipeViewModelComboBoxWraper>(); EntityInformation = new ObservableCollection <ViewModelEntityInformation>(); }
public void ServerTryClaimReward(IProtoEntity prototype) { Api.ValidateIsServer(); var reward = CompletionistSystemConstants.ServerRewardLearningPointsPerEntry; switch (prototype) { case IProtoItemFood protoItemFood: this.ServerTryClaimRewardInternal(this.ListFood, protoItemFood, reward, new DataEntryCompletionist(isRewardClaimed: true, protoItemFood)); break; case IProtoCharacterMob protoCharacterMob: this.ServerTryClaimRewardInternal(this.ListMobs, protoCharacterMob, reward, new DataEntryCompletionist(isRewardClaimed: true, protoCharacterMob)); break; case IProtoObjectLoot protoObjectLoot: this.ServerTryClaimRewardInternal(this.ListLoot, protoObjectLoot, reward, new DataEntryCompletionist(isRewardClaimed: true, protoObjectLoot)); break; case IProtoItemFish protoItemFish: var existingEntry = this.ListFish.FirstOrDefault(e => ReferenceEquals(protoItemFish, e.Prototype)); if (existingEntry.Prototype is null || existingEntry.IsRewardClaimed) { // no entry found or entry already claimed return; } var finishedEntry = new DataEntryCompletionistFish(isRewardClaimed: true, protoItemFish, maxSizeValue: existingEntry.MaxSizeValue); this.ServerTryClaimRewardInternal(this.ListFish, protoItemFish, reward, finishedEntry); break; default: throw new Exception("Unknown prototype: " + prototype); } }
public void ClientSetIconSource(IItem itemStorage, IProtoEntity iconSource) { var publicState = itemStorage.GetPublicState <ItemStoragePublicState>(); if (publicState.IconSource == iconSource) { return; } this.CallServer(_ => _.ServerRemote_SetIconSource(itemStorage, iconSource)); }
public ProtoEntityViewModel([NotNull] IProtoEntity entity) { ProtoEntity = entity; Title = entity.Name == "" ? entity.GetType().Name : entity.Name; TitleLower = entity.Name.ToLower(); Type = entity.Id; TypeLower = entity.Id.ToLower(); RecipeVMList = new FilteredObservableWithPaging <RecipeViewModel>(); UsageVMList = new FilteredObservableWithPaging <RecipeViewModel>(); EntityInformation = new ObservableCollection <ViewModelEntityInformation>(); }
private void ServerRemote_SetIconSource(IStaticWorldObject worldObjectCrate, IProtoEntity iconSource) { this.VerifyGameObject(worldObjectCrate); var character = ServerRemoteContext.Character; if (!this.SharedCanInteract(character, worldObjectCrate, writeToLog: true)) { return; } var publicState = GetPublicState(worldObjectCrate); publicState.IconSource = iconSource; }
/// <summary> /// Return reference to existed View Model. /// </summary> public static ProtoEntityViewModel GetEntityViewModel([NotNull] IProtoEntity entity) { if (!EntityDictionaryCreated) { throw new Exception("CNEI: Call GetEntityViewModel before all entity VMs sets."); } if (allEntityDictionary.ContainsKey(entity)) { return(allEntityDictionary[entity]); } else { throw new Exception("CNEI: Unknown entity type " + entity); } }
private static void AddIfNotContains( IProtoEntity prototype, NetworkSyncList <DataEntryCompletionist> list) { foreach (var entry in list) { if (ReferenceEquals(entry.Prototype, prototype)) { // already have an entry return; } } // add an entry list.Add(new DataEntryCompletionist(isRewardClaimed: false, prototype)); Api.Logger.Info("Completionist entry added: " + prototype.ShortId); }
public void AddValue(IProtoEntity source, StatName statName, double value) { if (value == 0d) { return; } StatsSources.RegisterValue(ref this.sources, source, statName, value); if (this.Values.TryGetValue(statName, out var currentValue)) { // simply sum with existing value value += currentValue; } this.ValidateIsNotReadOnly(); this.Values[statName] = value; }
public ViewModelWindowCrateIconSelector( IProtoEntity selectedProtoEntity, IReadOnlyCollection <IItem> existingItems, Action callbackSave, Action callbackCancel) { this.callbackCancel = callbackCancel; this.callbackSave = callbackSave; this.selectedProtoEntity = selectedProtoEntity; this.existingItems = existingItems; // no need to order as the ordering is applied later this.allItemsList = Api.FindProtoEntities <IProtoItem>().ToList(); this.existingItemsList = this.GetExistingItemsList(); this.RefreshLists(); }
private void ServerTryClaimRewardInternal <TDataEntry>( NetworkSyncList <TDataEntry> list, IProtoEntity prototype, ushort rewardLearningPoints, TDataEntry dataEntryWithClaimedReward) where TDataEntry : struct, ICompletionistDataEntry { var character = (ICharacter)this.GameObject; for (var index = 0; index < list.Count; index++) { var entry = list[index]; if (!ReferenceEquals(prototype, entry.Prototype)) { continue; } if (entry.IsRewardClaimed) { Api.Logger.Warning("Completionist: the reward is already claimed: " + prototype, characterRelated: character); return; } list.RemoveAt(index); list.Insert(index, dataEntryWithClaimedReward); Api.Logger.Info($"Completionist: the reward is claimed: {prototype}: +{rewardLearningPoints} LP", characterRelated: character); character.SharedGetTechnologies() .ServerAddLearningPoints(rewardLearningPoints, allowModifyingByStat: false); return; } Api.Logger.Warning( "Completionist: the reward cannot be claimed as the entry is not discovered: " + prototype, characterRelated: character); }
public void FillEffects(IProtoEntity prototype, BaseStatsDictionary effects, double maximumDefensePercent = 1) { Add(StatName.DefenseImpact, this.Impact); Add(StatName.DefenseKinetic, this.Kinetic); Add(StatName.DefenseExplosion, this.Explosion); Add(StatName.DefenseHeat, this.Heat); Add(StatName.DefenseCold, this.Cold); Add(StatName.DefenseChemical, this.Chemical); Add(StatName.DefenseRadiation, this.Radiation); Add(StatName.DefensePsi, this.Psi); void Add(StatName statName, double defensePercent) { if (defensePercent < 0 || defensePercent > maximumDefensePercent) { throw new Exception( $"Incorrect defense property value. It must be in range from 0 to {maximumDefensePercent} (inclusive). The defense {statName} for {prototype} is set to {defensePercent:F2}"); } effects.AddValue(prototype, statName, defensePercent); } }
public static ITextureResource GetIcon(IProtoEntity protoEntity) { if (protoEntity is null) { return(null); } var originalIcon = GetOriginalIcon(protoEntity); if (IconsCache.TryGetValue(originalIcon, out var weakReference) && weakReference.TryGetTarget(out var proceduralTexture)) { return(proceduralTexture); } proceduralTexture = new ProceduralTexture( "Crate icon " + protoEntity.ShortId, proceduralTextureRequest => GenerateIcon(proceduralTextureRequest, originalIcon), isTransparent: true, isUseCache: true, dependsOn: new[] { originalIcon }); IconsCache[originalIcon] = new WeakReference <ProceduralTexture>(proceduralTexture); return(proceduralTexture); }
protected RecipeViewModel([NotNull] IProtoEntity entity) : base(entity) { }
protected ProtoEntityWithRecipeBondsViewModel([NotNull] IProtoEntity entity) : base(entity) { }
public void AddPercent(IProtoEntity source, StatName statName, double percent) { if (percent == 0d) { return; } var multiplier = percent / 100d; if (this.IsMultipliersSummed) { // simply sum multipliers (like values) if (multiplier == 0) { return; } StatsSources.RegisterPercent(ref this.sources, source, statName, percent); if (this.Multipliers.TryGetValue(statName, out var currentMultiplier)) { // simply sum with existing value multiplier += currentMultiplier; } else { // non-existing multiplier - add base multiplier (one) multiplier += 1; } } else { if (multiplier <= -1) { // -100% or lower - wow! StatsSources.RegisterPercent(ref this.sources, source, statName, -100); this.Multipliers[statName] = 0; return; } StatsSources.RegisterPercent(ref this.sources, source, statName, percent); multiplier += 1; if (this.Multipliers.TryGetValue(statName, out var currentMultiplier)) { // Simply multiply multipliers. // We're doing this to avoid case when -50% + -50% = -100% // as it could broke the game in some cases (like movement speed). // But if percent is provided as -100%, then it will be converted to multiplier==0 // so we still can reset some stats to 0 by using percent effects. if (currentMultiplier == 0d) { // early return - the final multiplier also will be 0 and nothing changes return; } multiplier *= currentMultiplier; } } this.ValidateIsNotReadOnly(); this.Multipliers[statName] = multiplier; }