1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
583 | { |
583 | { |
584 | // This should not happen, but if it does, just merge the two. |
584 | // This should not happen, but if it does, just merge the two. |
585 | if (coin_objs [i]) |
585 | if (coin_objs [i]) |
586 | { |
586 | { |
587 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
587 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
588 | tmp->remove (); |
|
|
589 | coin_objs[i]->nrof += tmp->nrof; |
588 | coin_objs[i]->nrof += tmp->nrof; |
590 | esrv_del_item (pl->contr, tmp->count); |
|
|
591 | tmp->destroy (); |
589 | tmp->destroy (); |
592 | } |
590 | } |
593 | else |
591 | else |
594 | { |
592 | { |
595 | tmp->remove (); |
593 | tmp->remove (); |
596 | |
|
|
597 | if (pouch->type == PLAYER) |
|
|
598 | esrv_del_item (pl->contr, tmp->count); |
|
|
599 | |
|
|
600 | coin_objs[i] = tmp; |
594 | coin_objs[i] = tmp; |
601 | } |
595 | } |
602 | |
596 | |
603 | break; |
597 | break; |
604 | } |
598 | } |
… | |
… | |
646 | } |
640 | } |
647 | |
641 | |
648 | for (i = 0; i < NUM_COINS; i++) |
642 | for (i = 0; i < NUM_COINS; i++) |
649 | { |
643 | { |
650 | if (coin_objs[i]->nrof) |
644 | if (coin_objs[i]->nrof) |
651 | { |
|
|
652 | object *tmp = insert_ob_in_ob (coin_objs[i], pouch); |
645 | insert_ob_in_ob (coin_objs [i], pouch); |
653 | |
|
|
654 | esrv_send_item (pl, tmp); |
|
|
655 | esrv_send_item (pl, pouch); |
|
|
656 | |
|
|
657 | if (pl != pouch) |
|
|
658 | esrv_update_item (UPD_WEIGHT, pl, pouch); |
|
|
659 | |
|
|
660 | if (pl->type != PLAYER) |
|
|
661 | esrv_send_item (pl, pl); |
|
|
662 | } |
|
|
663 | else |
646 | else |
664 | coin_objs[i]->destroy (); |
647 | coin_objs[i]->destroy (); |
665 | } |
648 | } |
666 | } |
649 | } |
667 | |
650 | |
… | |
… | |
738 | SET_FLAG (op, FLAG_UNPAID); |
721 | SET_FLAG (op, FLAG_UNPAID); |
739 | return 0; |
722 | return 0; |
740 | } |
723 | } |
741 | else |
724 | else |
742 | { |
725 | { |
743 | object *tmp; |
|
|
744 | |
|
|
745 | CLEAR_FLAG (op, FLAG_UNPAID); |
726 | CLEAR_FLAG (op, FLAG_UNPAID); |
746 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
727 | CLEAR_FLAG (op, FLAG_PLAYER_SOLD); |
747 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
728 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
748 | tmp = merge_ob (op, NULL); |
|
|
749 | |
729 | |
750 | if (pl->type == PLAYER) |
730 | if (!merge_ob (op, op->env->inv)) |
751 | { |
|
|
752 | if (tmp) |
|
|
753 | { /* it was merged */ |
|
|
754 | esrv_del_item (pl->contr, op->count); |
|
|
755 | op = tmp; |
|
|
756 | } |
|
|
757 | |
|
|
758 | esrv_send_item (pl, op); |
731 | esrv_update_item (UPD_FLAGS, pl, op); |
759 | } |
|
|
760 | |
732 | |
761 | goto next_item; |
733 | goto next_item; |
762 | } |
734 | } |
763 | } |
735 | } |
764 | } |
736 | } |
… | |
… | |
806 | if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) |
778 | if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) |
807 | { |
779 | { |
808 | if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) |
780 | if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) |
809 | n = (pouch->weight_limit - pouch->carrying) / w; |
781 | n = (pouch->weight_limit - pouch->carrying) / w; |
810 | |
782 | |
811 | tmp = arch_to_object (at); |
783 | object *tmp = arch_to_object (at); |
812 | tmp->nrof = n; |
784 | tmp->nrof = n; |
813 | amount -= tmp->nrof * tmp->value; |
785 | amount -= tmp->nrof * tmp->value; |
814 | tmp = insert_ob_in_ob (tmp, pouch); |
786 | pouch->insert (tmp); |
815 | esrv_send_item (pl, tmp); |
|
|
816 | esrv_send_item (pl, pouch); |
|
|
817 | esrv_update_item (UPD_WEIGHT, pl, pouch); |
|
|
818 | esrv_send_item (pl, pl); |
|
|
819 | } |
787 | } |
820 | } |
788 | } |
821 | } |
789 | } |
822 | |
790 | |
823 | if (amount / at->value > 0) |
791 | if (amount / at->value > 0) |
824 | { |
792 | { |
825 | tmp = arch_to_object (at); |
793 | object *tmp = arch_to_object (at); |
826 | tmp->nrof = amount / tmp->value; |
794 | tmp->nrof = amount / tmp->value; |
827 | amount -= tmp->nrof * tmp->value; |
795 | amount -= tmp->nrof * tmp->value; |
828 | tmp = insert_ob_in_ob (tmp, pl); |
796 | pl->insert (tmp); |
829 | esrv_send_item (pl, tmp); |
|
|
830 | esrv_send_item (pl, pl); |
|
|
831 | } |
797 | } |
832 | } |
798 | } |
833 | } |
799 | } |
834 | |
800 | |
835 | if (amount != 0) |
801 | if (amount != 0) |
… | |
… | |
847 | |
813 | |
848 | if (amount > 0) |
814 | if (amount > 0) |
849 | { |
815 | { |
850 | object *tmp = arch_to_object (at); |
816 | object *tmp = arch_to_object (at); |
851 | tmp->nrof = amount; |
817 | tmp->nrof = amount; |
852 | tmp = insert_ob_in_ob (tmp, pl); |
818 | insert_ob_in_ob (tmp, pl); |
853 | esrv_send_item (pl, tmp); |
|
|
854 | esrv_send_item (pl, pl); |
|
|
855 | } |
819 | } |
856 | |
820 | |
857 | return 1; |
821 | return 1; |
858 | } |
822 | } |
859 | |
823 | |
… | |
… | |
862 | * buy item. |
826 | * buy item. |
863 | * |
827 | * |
864 | * Modified to fill available race: gold containers before dumping |
828 | * Modified to fill available race: gold containers before dumping |
865 | * remaining coins in character's inventory. |
829 | * remaining coins in character's inventory. |
866 | */ |
830 | */ |
867 | void |
831 | bool |
868 | sell_item (object *op, object *pl) |
832 | sell_item (object *op, object *pl) |
869 | { |
833 | { |
870 | sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; |
834 | sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; |
871 | |
835 | |
872 | if (pl == NULL || pl->type != PLAYER) |
836 | if (pl == NULL || pl->type != PLAYER) |
873 | { |
837 | { |
874 | LOG (llevDebug, "Object other than player tried to sell something.\n"); |
838 | LOG (llevDebug, "Object other than player tried to sell something.\n"); |
875 | return; |
839 | return false; |
876 | } |
840 | } |
877 | |
841 | |
878 | op->custom_name = 0; |
842 | op->custom_name = 0; |
879 | |
843 | |
880 | if (!amount) |
844 | if (!amount) |
881 | { |
845 | { |
882 | new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", query_name (op)); |
846 | new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", |
883 | |
847 | query_name (op)); |
884 | /* Even if the character doesn't get anything for it, it may still be |
848 | // elmex: change: the player now gets the item back if the shop is not |
885 | * worth something. If so, make it unpaid |
849 | // interested in it. |
886 | */ |
|
|
887 | if (op->value) |
|
|
888 | { |
|
|
889 | SET_FLAG (op, FLAG_UNPAID); |
|
|
890 | SET_FLAG (op, FLAG_PLAYER_SOLD); |
|
|
891 | } |
|
|
892 | |
|
|
893 | identify (op); |
|
|
894 | return; |
850 | return false; |
895 | } |
851 | } |
896 | |
852 | |
897 | /* We compare the price with the one for a player |
853 | /* We compare the price with the one for a player |
898 | * without bargaining skill. |
854 | * without bargaining skill. |
899 | * This determins the amount of exp (if any) gained for bargaining. |
855 | * This determins the amount of exp (if any) gained for bargaining. |
… | |
… | |
904 | if (extra_gain > 0) |
860 | if (extra_gain > 0) |
905 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
861 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
906 | |
862 | |
907 | pay_player (pl, amount); |
863 | pay_player (pl, amount); |
908 | |
864 | |
909 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); |
865 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", |
|
|
866 | query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); |
910 | pl->play_sound (sound_find ("shop_sell")); |
867 | pl->play_sound (sound_find ("shop_sell")); |
911 | |
868 | |
912 | SET_FLAG (op, FLAG_UNPAID); |
869 | SET_FLAG (op, FLAG_UNPAID); |
913 | identify (op); |
870 | identify (op); |
|
|
871 | |
|
|
872 | return true; |
914 | } |
873 | } |
915 | |
874 | |
916 | /* returns a double that is the ratio of the price that a shop will offer for |
875 | /* returns a double that is the ratio of the price that a shop will offer for |
917 | * item based on the shops specialisation. Does not take account of greed, |
876 | * item based on the shops specialisation. Does not take account of greed, |
918 | * returned value is between SPECIALISATION_EFFECT and 1. |
877 | * returned value is between SPECIALISATION_EFFECT and 1. |