/// <summary> /// Appraises an entity, returning it's price. /// </summary> /// <param name="uid">The entity to appraise.</param> /// <returns>The price of the entity.</returns> /// <remarks> /// This fires off an event to calculate the price. /// Calculating the price of an entity that somehow contains itself will likely hang. /// </remarks> public double GetPrice(EntityUid uid) { var ev = new PriceCalculationEvent(); RaiseLocalEvent(uid, ref ev, true); //TODO: Add an OpaqueToAppraisal component or similar for blocking the recursive descent into containers, or preventing material pricing. if (TryComp <MaterialComponent>(uid, out var material) && !HasComp <StackPriceComponent>(uid)) { if (TryComp <StackComponent>(uid, out var stack)) { ev.Price += stack.Count * material.Materials.Sum(x => x.Price * material._materials[x.ID]); } else { ev.Price += material.Materials.Sum(x => x.Price); } } if (TryComp <ContainerManagerComponent>(uid, out var containers)) { foreach (var container in containers.Containers) { foreach (var ent in container.Value.ContainedEntities) { ev.Price += GetPrice(ent); } } } return(ev.Price); }
private void CalculateStackPrice(EntityUid uid, StackPriceComponent component, ref PriceCalculationEvent args) { if (!TryComp <StackComponent>(uid, out var stack)) { Logger.ErrorS("pricing", $"Tried to get the stack price of {ToPrettyString(uid)}, which has no {nameof(StackComponent)}."); return; } args.Price += stack.Count * component.Price; }
private void CalculateMobPrice(EntityUid uid, MobPriceComponent component, ref PriceCalculationEvent args) { if (!TryComp <BodyComponent>(uid, out var body) || !TryComp <MobStateComponent>(uid, out var state)) { Logger.ErrorS("pricing", $"Tried to get the mob price of {ToPrettyString(uid)}, which has no {nameof(BodyComponent)} and no {nameof(MobStateComponent)}."); return; } var partList = body.Slots.ToList(); var totalPartsPresent = partList.Sum(x => x.Part != null ? 1 : 0); var totalParts = partList.Count; var partRatio = totalPartsPresent / (double)totalParts; var partPenalty = component.Price * (1 - partRatio) * component.MissingBodyPartPenalty; args.Price += (component.Price - partPenalty) * (state.IsAlive() ? 1.0 : component.DeathPenalty); }
private void CalculateStaticPrice(EntityUid uid, StaticPriceComponent component, ref PriceCalculationEvent args) { args.Price += component.Price; }